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

Why is my sword not dealing damage?

So I have a sword that I made. It plays the animation perfectly but it deals no damage when I use it. There are no errors or warnings. Here is the Local Script in the tool's handle:

repeat wait() until game.Players.LocalPlayer.Character
script.Parent.Parent.Equipped:Connect(function()
	local Anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
	script.Parent.Parent.Activated:Connect(function()
		Anim:Play()
		script.Parent.Parent.Damage.Value = true
		wait(1)
		Anim:Stop()
		script.Parent.Parent.Damage.Value = false
		script.Parent.Parent.Debounce.Value = true
	end)
end)

The Local Script works fine, but the Server Script in the sword's blade doesn't:

local db = script.Parent.Parent:WaitForChild("Debounce")
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Name == script.Parent.Parent.Parent.Name then
		else
			if script.Parent.Parent.Damage.Value == true then
				if db.Value == true then
					db.Value = false
					hit.Parent.Humanoid:TakeDamage(2)
				end
			end
		end
	end
end)

I followed a Youtube tutorial for this and just made a few modifications to their scripts.

Could someone please point out what I am doing wrong?

2 comments

0

whats the default value of your debounce

0

true

1 answer

Values don't replicate to the server, meaning that any changes made to NumberValues/StringValues/etc locally are not changed on the server.

If the default value for "Damage" is false, then even if you change it on the client it won't appear on the server.

The best way to do this would be to simply handle the debounce and the damage value on the server.

Local:

repeat wait() until game.Players.LocalPlayer.Character
script.Parent.Parent.Equipped:Connect(function()
    local Anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
    script.Parent.Parent.Activated:Connect(function()
        Anim:Play()
        wait(1)
        Anim:Stop()
    end)
end)

Server:

local debounce = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if hit.Parent.Name == script.Parent.Parent.Parent.Name then
        else
                if debounce == true then
                    debounce = false
                    hit.Parent.Humanoid:TakeDamage(2)
		    wait(1)
		debounce = true
                end
        end
    end
end)

2 comments

0

But wouldn't that mean that the Humanoid would take damage even when the animation isn't playing? So you can just go over and let the sword touch off a character and it deals damage?

0

I suppose it will work for now.

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