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

Player argument must be a player object?

I am working on a simulator and this error occurs. I don't know how to fix it. Also I am very bad at scripting

FireClient: player argument must be a Player object

Here's the script:

script.Parent.Touched:connect(function(part)
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    game.ReplicatedStorage.SellGrass:FireClient(plr)
end)

1 answer

✓ Accepted answer

Sometimes, an object that is not a descendant of a player touches it and fires the event. When you try to obtain a player from the part's parent, it won't be a player's character, so it'll return nil.

Do this:

script.Parent.Touched:connect(function(part)
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    if plr then
        game.ReplicatedStorage.SellGrass:FireClient(plr)
    end
end)

2 comments

0

I don't get the error anymore, but now this other script doesn't work. There is no error too.

0

Nevermind, I fixed it. Ty.

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