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

Filtering Enabled - FireClient() doesn't pass Player argument?

Hi, when I try to pass the player argument through FireClient it comes out with the error "FireClient: player argument must be a Player object", and I'm confused. Do I need to define the player beforehand for this to work?

Script

local function windows (player)
	if script.Parent.Occupant ~= nil then
		game.ReplicatedStorage.SeeThrough:FireClient(player)
	end
end

script.Parent.Touched:Connect(windows)

1 comment

0

Try script.Parent.Touched:Connect(windows(hit)) I'm not sure it will work, but you could try it.

1 answer

✓ Accepted answer

On the wiki, it shows that Touched returns one parameter, that is the part that touched, not the player object of the character that touched. To get the player object, you need to use GetPlayerFromCharacter, as shown below:

script.Parent.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) then --ensures that the part that touched is a character model and its a valid player’s character
            local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if script.Parent.Occupant ~= nil then
                  game.ReplicatedStorage.SeeThrough:FireClient(Player)
            end
      end
end)

2 comments

0

Nice answer, but couldn't you also do game.Players[hit.Parent.Name] although it could possibly lead to bugs.

0

yes, if a player is named as a property in Players, for example "MaxPlayers", that would cause some problem so it’s better to use GetPlayerFromCharacter

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