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

My Sword Won't Damage Humanoid?

The Sword animation works. however, the sword itself does not do damage. There is more to the Sword if you have questions.

script.Parent.blade.Touched:connect(function(p)
	if script.Parent.CanDamage == true then
		script.Parent.CanDamage.Value = false
		p.Parent.Humanoid:TakeDamage(20)
	end
end)

I am using R15.

1 comment

1

:Connect

1 answer

If CanDamage is a BoolValue as I suspect, you need to index the Value Property while comparing it.

But also, you don't know if it's always gonna be a character that touches. You have to set up precautions for this and check beforehand using another if statement.

And lastly, connect is deprecated. Use Connect

######note: remember to use variables when you find yourself repeating code!

local can = script.Parent:WaitForChild("CanDamage") --variable for convenience

script.Parent.blade.Touched:Connect(function(p) --Use Connect
	local h = p.Parent:FindFirstChild("Humanoid") --potential hum
	if h then --Check if it exists
		if can.Value then --index 'Value' property
			can.Value = false
			hum:TakeDamage(20)
		end
	end
end)

2 comments

0

It works. Thanks.

0

No problem ;D Happy developing!

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