I'm asking if I can damage everyone who touches that part in the same time, and damage not being glitchy, also without script.disabled and script.enabled since that's not very good for me...
COMMUNITY QUESTION
How to damage everyone who touches a part?
1 answer
Start off by using the Touched event.
script.Parent.Touched:connect(function(Hit)
return Hit
end)
This is a basic Touched event that fires when touched, The Hit parameter is a object that Interacts with the Part. Next, damage the player, but we'll check if Hit is a Player, by accessing the player and search for a Humanoid.
script.Parent.Touched:connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
return Hit
end
end)
Now the final step, taking damage, You can take damage by using the TakeDamage method.
Damage_Taken = 50
script.Parent.Touched:connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent.Humanoid:TakeDamage(50)
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
