Hello! what’s wrong in my code? how could i fix that?
local v = script.Parent
local t = false
v.Touched:Connect(function(player)
t = false
player.Parent:FindFirstChild("Humanoid").Health -= 20
t = true
wait(3)
end)
I need to make the player -20 hp each time (every 3 seconds) that the part is touched
local v = script.Parent
local t = true
v.Touched:Connect(function(player)
if t then
t = false
if player.Parent:FindFirstChild("Humanoid") then
player.Parent.Humanoid:TakeDamage(20)
end
wait(3)
t = true
end
end)
It seems you’re not checking if it’s a player so the script errors.
Here’s the fixed version
local v = script.Parent
local t = true
v.Touched:Connect(function(hit)
if t==true then
t= falsr
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health -= 20
wait(3)
t=true
end
end
end)
local v = script.Parent
local t = false
v.Touched:Connect(function(player)
if not t then
if player.Parent:FindFirstChildWhichIsA("Humanoid") then
player.Parent:FindFirstChildWhichIsA("Humanoid").Health -= 20
t = true
wait(3)
t = false
end
end
end)