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 5 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

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

script.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 — 5y

1 answer

Log in to vote
3
Answered by
LeadRDRK 437 Moderation Voter
5 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:

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)
0
Nice answer, but couldn't you also do game.Players[hit.Parent.Name] although it could possibly lead to bugs. Knineteen19 307 — 5y
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 — 5y
Ad

Answer this question