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?
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
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.
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