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

The touch event is not firing in a local script?

Asked by 3 years ago
script.Parent.Touched:Connect(function(hit)
    print("Touched")
    local d = hit.Parent:FindFirstChild("Humanoid")
    if d then
        script.Parent:Destroy()
        game.workspace.Spawn.Arrow:Destroy()
        print("Done")
    end
end)

so I tried the same code in a normal script and it worked but it's not working in a local script. what I'm trying to do is to make the parts get destroyed only for the client but it's not working. my goal is to just make the parts disappear for the client only whenever the player touches the part.

0
use a remoteevent, because  script.Parent.Touched wont work on the client JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

You can't use touched in a localscript

So we're gonna use a remote event

Server Script

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then

        script.Parent:Destroy()
        game:GetService("ReplicatedStorage"):FindFirstChild("DestroyArrow"):FireClient(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent))

    end
end)

Local Script

game:GetService("ReplicatedStorage"):FindFirstChild("DestroyArrow").OnClientEvent:Connect(function()

    game.Workspace.Spawn.Arrow:Destroy()
    print("Done")

end)
0
Thanks for the accepted answer MattVSNNL 620 — 3y
Ad

Answer this question