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

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

Asked by 6 years ago

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

1local function windows (player)
2    if script.Parent.Occupant ~= nil then
3        game.ReplicatedStorage.SeeThrough:FireClient(player)
4    end
5end
6 
7script.Parent.Touched:Connect(windows)
0
Try script.Parent.Touched:Connect(windows(hit)) I'm not sure it will work, but you could try it. Knineteen19 307 — 6y

1 answer

Log in to vote
3
Answered by
LeadRDRK 437 Moderation Voter
6 years ago

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:

1script.Parent.Touched:Connect(function(hit)
2      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
3            local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
4            if script.Parent.Occupant ~= nil then
5                  game.ReplicatedStorage.SeeThrough:FireClient(Player)
6            end
7      end
8end)
0
Nice answer, but couldn't you also do game.Players[hit.Parent.Name] although it could possibly lead to bugs. Knineteen19 307 — 6y
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 LeadRDRK 437 — 6y
Ad

Answer this question