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

Boolean value is not working for simple sword script?

I already have the local script with the animations and all and it's working perfectly fine. But for the damaging part (when the sword touches an player) it's supposed to damage them but it's not working. Here is the script:

candamage = true
script.Parent.Touched:Connect(function(toucH)
	local f = toucH.Parent:FindFirstChild("Humanoid")
	if f and candamage == true and script.Parent.Parent.swingdmg.Value == true then
	candamage = false
	f:TakeDamage(20)
	wait(1.2)
	candamage = true
	end
end)

What's supposed to happen is I only want the other player to be damaged ONLY when I swing the sword. So I put a bool value, and the swinging animation works but the other player does not take DAMAGE at all.

Any help?

1 answer

First, try the basics: remove everything from the if statement aside from 'if (f)' and then do 'f:TakeDamage()' If that works, try it with your candamage debounce variable. If that works, it might be your swing damage value.

If you get stuck at any of those steps, tell me in the comments of this answer.

2 comments

0

It is my boolvalue that's messing everything up but I don't understand why. The local script with the animations and all changes the bool value to true then false after 1.2 seconds. In my script it says that IF the bool value is true then it will damage the other person but it's not damaging them? Any help :(

0

Can you add the bit of code where you change the value to true?

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