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

FireClient: player argument must be a Player Object?

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

✓ Accepted answer

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)

2 comments

0

Appreciate the help. Thought the argument hit was a player

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