Hello everyone, so I made a combat script that triggers a RemoteEvent to do damage, it works. But the problem is the damage still continues after the RemoteEvent?

Any Idea why?

In ServerScriptServer

local CombatEvent = game.ReplicatedStorage.Events.LeftHand


local function Combat(Player)
	local dmg = true
	Player.Character["Left arm"].Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and dmg == true then
    hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health-5
    dmg = false
    wait(0.5)
end
end)
end
dmg = false
CombatEvent.OnServerEvent:Connect(Combat)

7 comments

0

First off - why are you relying on Touched for something as important as combat, this is not a good practice. Also, you should probably elaborate more - what circumstance must be met for this remote to be called?

0

Ok, the reason for this either is that you repeatedly fire the remote without a debounce, or you are hitting multiple body parts of the same person, thus triggering the event multiple times, or both

0

And why are you nesting Touched inside OnServerEvent? That just creates a new connection each time OnServerEvent is fired.

0

Well i'm not sure how to do it any other way, not the best scripter

0

What does the client need to do to fire this event? Click their mouse?

0

yes

0

It's possible that Touched is being fired multiple times before dmg is changed to false. This whole setup is a bit strange and wonky - when you say damage is still being dealt after the function is called, do you simply mean that more than 5 damage has been dealt?