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

I'm getting a FireClient: player argument must be a Player object error, how could i prevent this?

This is my server script:

local players =game:GetService("Players")
local tpp1 = script.Parent
local tpp2 = game.Workspace.teleportPart2
local debounce = false
local location = tpp2.CFrame
local rs = game.ReplicatedStorage
local tweenEvent = rs.TweenGui


function steppedOnTpp1(hit)
	local hitParent = hit.Parent
	local humanoid = hitParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		if debounce == false then
			debounce = true
			tweenEvent:FireClient(hitParent)
		   humanoid.Torso.CFrame = location + Vector3.new(0, 4, 0)
			wait(3)
			debounce = false
		end
	
	end
	
end

tpp1.Touched:Connect(steppedOnTpp1)

And then, I tested it on the local script in the frame here:

local frame = script.Parent
local rs = game.ReplicatedStorage

rs.TweenGui.OnClientEvent:Connect(function()
	print("Received Event.")
end)

How can I solve this error?

1 answer

✓ Accepted answer

You need to pass a Player Instance to :FireClient

local players =game:GetService("Players")
local tpp1 = script.Parent
local tpp2 = game.Workspace.teleportPart2
local debounce = false
local location = tpp2.CFrame
local rs = game.ReplicatedStorage
local tweenEvent = rs.TweenGui


function steppedOnTpp1(hit)
    local hitParent = hit.Parent
    local humanoid = hitParent:FindFirstChildWhichIsA("Humanoid")
    local player = players :GetPlayerFromCharacter(hitParent) -- try to get a player instance based on the character that hit
    if humanoid and player then -- if its a valid player
        if debounce == false then
            debounce = true
            tweenEvent:FireClient(player) -- use :FireClient on the player
           humanoid.Torso.CFrame = location + Vector3.new(0, 4, 0)
            wait(3)
            debounce = false
        end

    end

end

tpp1.Touched:Connect(steppedOnTpp1)

1 comment

0

Thank you so much.

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