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

FireClient: player argument must be a Player Object?

Asked by
TechModel 118
2 years ago

The script is a portal area where it is enabled to teleport people somewhere and sends a remote event to the client saying "This area is restricted". But the issue on line 10 in the output says: "FireClient: player argument must be a Player Object" not sure what that means.

local Teleport = "BackOut"
local Pos = script.Parent.Parent:FindFirstChild(Teleport)

function Touch(hit)

    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        hit.Parent:MoveTo(Pos.Position)
        game.ReplicatedStorage.NotifyRemotes.BankTime:FireClient(hit)
    end
end

script.Parent.Touched:Connect(Touch)

1 answer

Log in to vote
2
Answered by
LeHelary 142
2 years ago

It means when you use the FireClient() function, the first argument must be the player that receives the event. When you use FireAllClients(), all clients will receive that event and will call the functions connected to that event.. however with FireClient() only one player receives the event, and you must specify which player (as argument #1, for example someRemoteEvent:FireClient(plr)). So how do you get the player in your script? You use GetPlayerFromCharacter().

local Players = game:getService("Players") -- Added Players Service
local Teleport = "BackOut"
local Pos = script.Parent.Parent:FindFirstChild(Teleport)

function Touch(hit)

    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        hit.Parent:MoveTo(Pos.Position)
    local plr = Players:GetPlayerFromCharacter(hit.Parent) -- Get The Player
        game.ReplicatedStorage.NotifyRemotes.BankTime:FireClient(plr, hit) -- Send Event (not sure if you need the value of 'hit' as argument, but if you do you should leave it like this)
    end
end

script.Parent.Touched:Connect(Touch)
Ad

Answer this question