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?" Even though it is??

It basically says that the first argument has to be the player, which it is? Unless I'm wrong but I don't see how I could fix this?

Error: "FireClient: player argument must be a Player object?"

Serverscript In Tool

local Projectile = script.Parent
local Heartbeat = game:GetService("RunService").Heartbeat

while Heartbeat:wait() do
	Projectile.CFrame = CFrame.new(Projectile.Position, Projectile.Position + Projectile.Velocity)
	Projectile.Touched:connect(function(hit)
		
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		local Model = game.ReplicatedStorage.Morphs.SweetCheeks
		
		local Event = game.ReplicatedStorage.Events.Morph
		
		Event:FireClient(Player, Model)
		
	end)
end

1 comment

0

You need to filter for the Character Object before using it to uplink a player. This can be done by searching hit.Parent for a Humanoid Object, occasionally provided a secondary Parent climb for potential accessory overlap.

3 answers

✓ Accepted answer

you shouldn't have a function inside a loop, since it will continuously create a new function when it really isn't necessary. you also need to have the Touched event check if the part touching is an actual player so that it can fire.

fix:

local Projectile = script.Parent
local Heartbeat = game:GetService("RunService").Heartbeat

while Heartbeat:wait() do
	Projectile.CFrame = CFrame.new(Projectile.Position, Projectile.Position + Projectile.Velocity)
end

Projectile.Touched:Connect(function(hit)
	if hit and hit.Parent and hit.Parent:IsA('Model') and hit.Parent:FindFirstChild('Humanoid') then
		local Player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
		local Model = game:GetService('ReplicatedStorage').Morphs.SweetCheeks
		local Event = game:GetService('ReplicatedStorage').Events.Morph
		Event:FireClient(Player, Model)
	end
end)

3 comments

0

Still shows "FireClient: player argument must be a Player object"

0

I printed the Player, it outputs as a Nil value

0

It does sorta work, but the morph doesn't work still so I gotta work on that

Morph Script

local event = game.ReplicatedStorage.Events.Morph

event.OnServerEvent:Connect(function(player, model)
	print("--------")
	print("Player: "..player)
	print("--------")
	print("Morph: "..model)
	print("--------")
	local Char = model:Clone()
	local Pos = player.Character:GetPrimaryPartCFrame()
	local Schar = game.StarterPlayer:FindFirstChild("StarterCharacter")
	game:GetService("StarterPlayer")
	player.Character:Destroy()
	player.Character = Char
	Char.Parent = workspace
	local p = Char:Clone()
	p.Parent = game.StarterPlayer
	Char:SetPrimaryPartCFrame(Pos)
	Schar:Destroy()
	wait(30)
	
end)

1 comment

0

what lol

If your projectile system is working then you first need to check if it is a player or not.

local Projectile = script.Parent
local Heartbeat = game:GetService("RunService").Heartbeat

while Heartbeat:wait() do
    Projectile.CFrame = CFrame.new(Projectile.Position, Projectile.Position + Projectile.Velocity)
    Projectile.Touched:connect(function(hit)

        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if not Player then return nil end

        local Model = game.ReplicatedStorage.Morphs.SweetCheeks

        local Event = game.ReplicatedStorage.Events.Morph

        Event:FireClient(Player, Model)

    end)
end

If the player variable wasn't an actual player, then the script will still run until there is an function, or property you want to change about the player. Or in all together anything that needs the player for some reason.

Sometimes functions return nil for a reason. They want to indicate that the following value isn't not found or returned.

If I didn't provide a right answer or it still does not work you can ask me

2 comments

0

It doesn't seem to be firing the event? I added a print to check and nothing appears in the output, no error either?

0

Also I checked what the player was, it comes out as a nil?

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