You can write your topic however you want, but you need to answer these questions:
-
When I touch a part, it should play a sound and start taking damage, but when you leave the part it stops.
-
It does not stop the sound and damage if debounce is in there.
local touching
local db = true
game.Workspace.Part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
touching = true
if db == true then
db = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
while touching == true do
player.Character.Humanoid:TakeDamage (1)
player.Character.Health.Disabled = true
game.Workspace.Sound:Play()
wait(10)
db = true
end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
end
end
end)
game.Workspace.Part.TouchEnded:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
touching = false
if db == true then
db = false
print("test")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
hit.Parent.Humanoid:TakeDamage (0)
player.Character.Health.Disabled = false
game.Workspace.Sound:Stop()
db = true
end
end
end
)