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`
** You are now Level 1! **