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

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

My Idle animation won't stop working because my getPlayer function won't get the actual player? I'm not sure why it won't get the player!?

Serverscript in tool

local Tool = script.Parent
local Remote = Tool:WaitForChild("Remote")
local Handle = Tool:WaitForChild("Handle")
local Mesh = Handle:WaitForChild("Mesh")

 

local Equipping = false
local Grip = nil

local StraightMeshData = "http://www.roblox.com/asset/?id=193827643"
local StraightGripPos = Vector3.new(0, 0, 1.5)
local BentMeshData = "http://www.roblox.com/asset/?id=193827593"
local BentGripPos = Vector3.new(0, 0.6, 0.5)
local Bent = true

local AttackAble = true
local AttackRestTime = 1
local AttackVictims = {}
local AttackWindow = 0.66
local AttackDamaging = false
local AttackWindup = 0.1

function getPlayer()
	local char = script.Parent.Parent
	return game:GetService("Players"):GetPlayerFromCharacter(char)
end

function contains(t, v)
	for _, val in pairs(t) do
		if val == v then
			return true
		end
	end
	return false
end

function tagHuman(human)
	local tag = Instance.new("ObjectValue")
	tag.Value = getPlayer()
	tag.Name = "creator"
	tag.Parent = human
	game:GetService("Debris"):AddItem(tag)
end

function normal()
	
	if not AttackAble then return end
	
	--rest
	AttackAble = false
	delay(AttackRestTime, function()
		AttackAble = true
	end)
	
	--damage
	delay(AttackWindup, function()
		AttackVictims = {}
		AttackDamaging = true
		delay(AttackWindow, function()
			AttackDamaging = false
		end)
	end)
	
	Handle.Swing:Play()
	
	local t = math.random(1, 2)
	if t == 1 then
		Remote:FireClient(getPlayer(), "PlayAnimation", "Swing1")
		Handle.Trail.Enabled = true
	elseif t == 2 then
		Remote:FireClient(getPlayer(), "PlayAnimation", "Swing2")
		Handle.Trail.Enabled = true
	end
		
end

function onEquip()
	if Equipping then return end
	Equipping = true
	
	--animation
	Remote:FireClient(getPlayer(), "PlayAnimation", "Idle")
	Handle.Trail.Enabled = false
	Equipping = false
end

function onUnequip()
	if Grip then
		Grip:Destroy()
	end
	
	--animation
	Remote:FireClient(getPlayer(), "StopAnimation", "Idle")
end

function onRemote(player, func, ...)
	if player ~= getPlayer() then return end
	
	if func == "NormalStart" then
		normal()
	end
end

Tool.Equipped:connect(onEquip)
Tool.Unequipped:connect(onUnequip)
Remote.OnServerEvent:connect(onRemote)

8 comments

0

can you try printing out: print(getPlayer()) and then print(getPlayer().Parent) ?

0

Did you try debugging? Maybe using the print function at certain points in your getPlayer() function? Or after it's called?

0

do u even read bruh i just said that

0

You asked if you could. I said you can. Stop being arrogant, you came here for answers, your script is messy and it hurts my eyes to read it. If you want to solve your issue, learn to script like everyone who scripts did. It's called reading the roblox developer API page :)

0

Oops, sorry. I'm not the original poster. I also meant the 'do u even read' comment sarcastically since I already told him to try printing but, bad wording by me and you explained well. Srry.

0

I fixed it

0

yay

0

please let ppl know what you did to fix it in the comments or answer tab. i'll mark your solution as the answer.

1 answer

I fixed this error by changing the GetPlayer() to script.Parent.

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