Can somebody help me with this script?

So I’m trying to make a script where when the player has a certain item out and touched a part, it will fire a remote event on the client side. I’m very bad at scripting and I don’t know a solution to an error shown below. Could somebody please help me with this?


errorcode

1 Like

Well, what I would do is this:

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent:FindFirstAncestor("Chainsaw") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
RemoteEvent:FireClient(player)
end
end)

Not sure if this would work since I didn’t test in studio let me know if it does or if you get any errors

2 Likes

It didn’t work, I tested it out and it seems to be getting stuck at the
“if hit.Parent:FindFirstAncestor(“Chainsaw”) then” part. The script doesn’t progress farther then that. I double checked the spelling of the tool and it’s all right.

1 Like

Try this maybe?

script.Parent.Touched:Connect(object) -- this fires what part touched the part not what player touched the part btw
    if object:FindFirstAncestorWhichIsA("Model") and object:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then
       local character = object:FindFirstAncestorWhichIsA("Model")
       local player = game.Players:GetPlayerFromCharacter(character)
       RemoteEvent:FireClient(player)
    end
end
1 Like

Are you getting any errors in the output?

1 Like

Make sure it says FireClient not FireCilent Lol

1 Like

No, it doesn’t output any errors or other things like that.

1 Like

I fixed it myself, thanks to everybody who responded!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.