Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Txeer 46
4 years ago

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

Log in to vote
0
Answered by
Txeer 46
4 years ago

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
0
Mark it as the answer! ankurbohra 681 — 4y
0
It doesn't give me the option Txeer 46 — 4y
Ad

Answer this question