So the problem is here that you are disabling the script that you need to run. Easy fix.
So a little insight here, the function wait() stalls the script. But we have an event here.
Events I think do listen even if the script is stalled by a wait()
To do this we disconnect the event.
By the way when events are listening while a wait() is being executed it will fire that amount of times it has listened to. E.g the event listens 7 times while wait() is executed, after that wait()
the event will fire 7 times.
This may seem weird but we can make an event a variable. For this we need to connect the event differently.
local function onTouch(hit)
local char = hit.Parent
local hum = char:FindFirstChild("Humanoid")
if hum and char.Name ~= script.Parent.Parent.Parent.Name and hum ~= nil then
hum.Health = hum.Health - script.Dmg.Value
TouchEvent:Disconnect()
wait(0.5)
TouchEvent = script.Parent.Touched:Connect(onTouch)
end
end)
TouchEvent = script.Parent.Touched:Connect(onTouch)
I bet you are confused right now but we are saying a reference to the part being touched, if we find a humanoid we will disconnect the event so no more times it can call. Then after .5 seconds we will reconnect and carry on.
Check this roblox wiki link for more on events:
https://developer.roblox.com/en-us/articles/events
The reason disabling the script is dangerous as say you are printing some stuff.
print("cats")
script.Disabled = true
script.Disabled = false
print("cats")
1 comment
I see what you are thinking but that would make it fire spontaneously.