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

Why will this sword not detect when it is being touched?

I am scripting a sword and trying to make it function. One of the obvious functions is that a player will take damage when touched by the sword. I have a local script inside the handle of tool and it is supposed to detect when it is touched, it isn't.

Script:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent == not game.Players.LocalPlayer.Character then
		print("hit")
		game.ReplicatedStorage.RemoteEvents.TakeDamage:FireServer(hit.Parent:FindFirstChild("Humanoid"), 20)
	end
end)

1 answer

This was an idiotic problem. I solved it by changing it like this:

-- old code
if hit.Parent == not game.Players.LocalPlayer.Character then

-- new code
if hit.Parent ~= game.Players.LocalPlayer.Character then

2 comments

0

Mark it as the answer!

0

It doesn't give me the option

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