Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how would I make this script not hit more than once? (.Touched hitting multiple times)

remote = game.ReplicatedStorage.RemoteEvents:WaitForChild("SwordSlashRemote")
remote.OnServerEvent:Connect(function(plr, sword, playing, wow)
	
	sword.Blade.Touched:Connect(function(part)
			if not wow then
				if part:FindFirstAncestor("Username for testing") then
					if part.Parent:FindFirstChild("Humanoid") then
						part.Parent.Humanoid:TakeDamage(30)
						wow = true
						wait(0.2)
						wow = false
				end
			end
		end
	end)
end)

this is a script that responds to the SwordSlashRemote in replicatedstorage, it is fired every time you play an animation with a sword, I was wondering how to stop it from hitting multiple times, for now the wait(0.2) isn't very helpful because it still hits more than once sometimes.

1 comment

0

Perhaps increasing the wait time would do.

2 answers

Hello! I'm BlackOrange and I will be helping!

To start off:

You should set wow (your debounce) to true Immediately, why would you do it after the Damage has been done? It doesn't stop it.

So:

Taking what you have I have re-modified your code:

local remote = game.ReplicatedStorage.RemoteEvents:WaitForChild("SwordSlashRemote") -- please use local variables
remote.OnServerEvent:Connect(function(plr, sword, playing, wow)

    sword.Blade.Touched:Connect(function(part)
            if not wow then
		wow = true
                if part:FindFirstAncestor("Username for testing") then
                    if part.Parent:FindFirstChild("Humanoid") then
                        part.Parent.Humanoid:TakeDamage(30)
                        wait(0.3) -- Increased a bit just in case
                end
		wow = false
            end
	    -- Put here if no work wow = false
        end
    end)
end)

This should do the trick, looking at what you know currently it seems like I don't need to explain.

If it doesn't work, check output and the error should be a simple quick fix.

Another fix may be changing wow = false to the end below

Best of luck

-- BlackOrange3343

1 comment

0

thank you for trying to help, still facing the same problem but you deserve an upvote

I think you should add...

script.Parent.Destory()

or...

(whatever your local is) = false

This discussion is preserved as it was. New answers, comments, and votes are closed.