Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script keep doing damage in serverscriptservice?

Asked by 6 years ago

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)
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? SummerEquinox 643 — 6y
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 theking48989987 2147 — 6y
0
And why are you nesting Touched inside OnServerEvent? That just creates a new connection each time OnServerEvent is fired. User#19524 175 — 6y
0
Well i'm not sure how to do it any other way, not the best scripter klean10 4 — 6y
View all comments (3 more)
0
What does the client need to do to fire this event? Click their mouse? SummerEquinox 643 — 6y
0
yes klean10 4 — 6y
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? SummerEquinox 643 — 6y

Answer this question