How can I make this to only damage the same player once?
x.Touched:connect(function(hit) if x.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid").Health > 0 then x.Parent.Humanoid.Health = hit.Parent.Humanoid.Health-10
local PlayersHitted = {} local x = script.Parent -- Assuming your script is inside the part, change otherwise x.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid").Health > 0 then for i,tableValue in pairs(PlayersHitted) do if tableValue == hit.Parent.Name then return end end table.insert(PlayersHitted, hit.Parent.Name) hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health-10 end end)
Tested it on studio, it works.
What we are doing here is store the name of every player who touches the brick, therefor whenever the brick gets touched by the same player again it will first check for the stored names and if the player's name matches any of the stored names (which, since its the same player, it will) then the brick doesnt deal any damage.
Best regards!
local lastPersonHit = nil x.Touched:Connect(function(hit) if x.Parent:FindFirstChild('Humanoid') and hit.Parent:FindFirstChild('Humanoid').Health > 0 and lastPersonHit ~= hit.Parent.Name then lastPersonHit = hit.Parent.Name x.Parent.Humanoid.Health:TakeDamage(10) end end)