Player Argument must be a Player Object - Server Script

Okay so, I have a RemoteEvent that fires when the player unequips a Tool and when it fires the “Player Argument must be a Player Object” error message pops up. I’ve tried looking at similar posts but they didn’t have the answer I was searching for.

Here’s my code; this is a server script.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents", true)
local EventEnable = RemoteEvents:FindFirstChild("MagnifyingEventEnable", true)
local EventDisable = RemoteEvents:FindFirstChild("MagnifyingEventDisable", true)

local Tool = script.Parent

Tool.Equipped:Connect(function()
	EventEnable:FireClient(Players:GetPlayerFromCharacter(Tool.Parent))
end)

Tool.Unequipped:Connect(function()
	EventDisable:FireClient() --// This is the line that errors.
end)

Client side:

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui

local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents", true)
local EventEnable = RemoteEvents:FindFirstChild("MagnifyingEventEnable", true)
local EventDisable = RemoteEvents:FindFirstChild("MagnifyingEventDisable", true)

EventEnable.OnClientEvent:Connect(function()
	local Main = PlayerGui:FindFirstChild("MainGui", true)
	local ItemVignette = Main:FindFirstChild("ItemVignette", true)
	ItemVignette.ImageColor3 = Color3.fromRGB(125, 70, 255)
	local Tween = TweenService:Create(ItemVignette, TweenInfo.new(1), {ImageTransparency = 0.65})
	Tween:Play()
end)

EventDisable.OnClientEvent:Connect(function()
	print("hi")
end)

Show us the client side aswell, [where you called OnClientEvent].

I just edited it to show the client side.

It’s showing an error message because you are not specifying which client when you call fire client.

Try this

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local EventEnable = RemoteEvents:FindFirstChild("MagnifyingEventEnable")
local EventDisable = RemoteEvents:FindFirstChild("MagnifyingEventDisable")

local Tool = script.Parent
local Client

Tool.Equipped:Connect(function()
	Client = Players:GetPlayerFromCharacter(Tool.Parent)
	EventEnable:FireClient(Client)
end)

Tool.Unequipped:Connect(function()
	EventDisable:FireClient(Client)
end)

It worked; thanks for the help.

1 Like