#Parts of script not functioning but no errors

30 messages · Page 1 of 1 (latest)

forest terrace
#

I'm making a project where there are multiple machines (now called generators) which you can damage. After damaging a generator 4 times, it should turn off, make some sounds and then add 1 to a global variable.

I can hear sounds when damaging the generator, but nothing happens after damaging it 4 times. I have a feeling the variables aren't working. I'm still fairly new to Luau but I was hoping someone can help me!

Here's my code:
`local ProximityPrompt = game:GetService("Workspace").Generator.Base.Attachment.ProximityPrompt

generators_broken = 0
local model = script.Parent
local prompt = model.Base.Attachment.ProximityPrompt
local gem = model.Holder.Shard
local gemL = model.Holder.Attachment.PointLight
local damages_done = 0

prompt.ActionText = "Damage"
ProximityPrompt.Triggered:Connect(function(player)
if damages_done <= 4 then
model.Base["damage"]:Play()
damages_done += 1
end
end)

if damages_done >= 4 then
prompt.Enabled = false
model.Base["explosion"]:Play()
model.Base.engine.Looped = false
model.Base["engine off"]:Play()
model.Base["blast"]:Play()
generators_broken += 1
end`

lost marsh
#

I'll try to help you, but maybe I won't be of much help.

#

Ohh, wait a minute

#

have you tried to print the global value after interact with a reactor?

desert torrent
#

you should put a value

#

in each reactor/generator

#

then each time proxprompt finishes subtract one from the value

#

if value is 0 then destroy reactor and add one to destroyed reactor thingies

forest terrace
forest terrace
desert torrent
#

damages done applies to ALL 4 reactors

#

if the script you sent is only for one reactor

#

then make broken reactor an actual value

forest terrace
#

This was just for one single reactor

desert torrent
desert torrent
#

and change it by one

forest terrace
#

How would I do that?

lost marsh
#

just add a number value in a service

#

or in the generator

desert torrent
#

yeah

lost marsh
#

so yeah, i did something like your script in a random place and it's working

forest terrace
#

Weird..

opaque hullBOT
#

studio** You are now Level 1! **studio

lost marsh
#

generators_broken = 0
local damages_done = 0

ProximityPrompt.ActionText = "Damage"
ProximityPrompt.Triggered:Connect(function(player)
    if damages_done <= 4 then
        damages_done = damages_done + 1
    end
    if damages_done >= 4 then
        ProximityPrompt.Enabled = false
        generators_broken = generators_broken + 1
        script.Value.Value = script.Value.Value + 1
    end
    print(script.Value.Value)
end)

-- smaller version of the script```
forest terrace
#

I have found the problem, thanks to your code!

#

I had put the if damages_done... under the entire proximity prompt function

#

So it never got executed

lost marsh
#

ohh, ok bro, be safe!

forest terrace
#

Thanks a lot, both of you!