FireClient: player argument must be a Player object. Why does it say my argument has to be a player?

Hello there, I have been trying to figure out how to make my GUI work with the client-server model I followed the documentation HERE and even then it gives me this error for some reason I do not know why. The goal of my UI is pretty simple using good practices for my code and make the number go up when I use MouseButton1Click when a player clicks on it to increase the stat. I have also read the forums to try and find my answer and I did see some posts about this but none of them really answered to what I wanted from what I have checked.

Here is the 2 scripts (Server and Client)

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

local CashButton = game.StarterGui.StatGUI.Frame.CashButton
local CashAmount = game.StarterGui.StatGUI.Frame.CashAmount

local Stats = {
    Cash = 0,
    Increase = 1
}

local function OnPlayerCashClick(player)
    local Cash = Stats.Cash
    Stats.Cash = Stats.Cash + Stats.Increase
    CashUpdater:FireClient(player, Cash)
end

CashButton.MouseButton1Click:Connect(OnPlayerCashClick())
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local CashUpdater = ReplicatedStorage:WaitForChild("CashUpdater")

local player = Players.LocalPlayer

local CashButton = game.StarterGui.StatGUI.Frame.CashButton
local CashAmount = game.StarterGui.StatGUI.Frame.CashAmount

local function CashUpdate(Cash)
    CashUpdater.OnClientEvent:Connect(CashUpdate)
    player.PlayerGui.StatGUI.Frame.CashAmount.Text = Cash .. " Cash"
    print(Cash)
end

CashUpdater.OnClientEvent:Connect(CashUpdate)
CashButton.MouseButton1Click:Connect(CashUpdate)

Thanks in advance!

– Scripteor

The Variable Player is not specified as the Player according to the script
Instead the game believes its any (Anything)

You may need to find a way to get the Player

I followed the documentation though I really don’t get it I thought it would of worked but I guess not haha.

Looking at the documentation, you were supposed to do this:

local function onPlayerAdded(player)
   print("[Server] Firing event to player", player.Name)
   remoteEvent:FireClient(player, Players.MaxPlayers, Players.RespawnTime)
end
Players.PlayerAdded:Connect(onPlayerAdded)

The First Argument to the PlayerAdded Event is the Player itself

Yeah, I did not want onPlayerAdded only difference. I do not want it to run once when it starts up I want it to run with the MouseButton1Click :/.

Cant you use FireAllClients?

Text

Why are you accessing the UI through StarterGUI on the LocalScript? Access it through the players PlayerGUI, using player.PlayerGui.

You do not need the double parantheses after OnPlayerCashClick

LocalScript only makes changes to the player, not the Server, shouldnt be an issue

They both work the same

1 Like

Nope I want it separate on each client. I made another GUI before but the Roblox updates broke it. Anyways it was doing this error of giving stats to everyone.

I put it in StarterGui because I could not find the PlayerGui folder which only appears when players are in game right?

Where did you place this script to?

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

local CashButton = game.StarterGui.StatGUI.Frame.CashButton
local CashAmount = game.StarterGui.StatGUI.Frame.CashAmount

local Stats = {
    Cash = 0,
    Increase = 1
}

local function OnPlayerCashClick(player)
    local Cash = Stats.Cash
    Stats.Cash = Stats.Cash + Stats.Increase
    CashUpdater:FireClient(player, Cash)
end

CashButton.MouseButton1Click:Connect(OnPlayerCashClick()) -- No Player Argument

ServerScriptService is where I put that code :slight_smile: .

How about try :FireServer()

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

local CashButton = game.StarterGui.StatGUI.Frame.CashButton
local CashAmount = game.StarterGui.StatGUI.Frame.CashAmount

local Stats = {
    Cash = 0,
    Increase = 1
}

local function OnPlayerCashClick(player)
    local Cash = Stats.Cash
    Stats.Cash = Stats.Cash + Stats.Increase
    CashUpdater:FireClient(player, Cash)
end

CashUpdater.OnServerEvent:Connect(OnPlayerCashClick)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local CashUpdater = ReplicatedStorage:WaitForChild("CashUpdater")

local player = Players.LocalPlayer

local CashButton = game.StarterGui.StatGUI.Frame.CashButton
local CashAmount = game.StarterGui.StatGUI.Frame.CashAmount

local function CashUpdate(Cash)
    player.PlayerGui.StatGUI.Frame.CashAmount.Text = Cash .. " Cash"
    print(Cash)
end

CashUpdater.OnClientEvent:Connect(CashUpdate)
CashButton.MouseButton1Click:Connect(function()
    CashUpdater:FireServer()
end)

It puts an error at the : end) I have also tried without it not much more luck with that :p.

What how is that an error, maybe send a place file then I will look at the errors

How do I do that I am a pretty big noob with devforum also do not judge the UI I do not really like doing front end designing lol.

Not sure where you’re getting the value of Cash here. text = Cash … " Cash"
Also not really sure what you’re doing …

local script in starterGui (inside the CashButton)

local cashButton = script.Parent
local cashAmount = cashButton.Parent.CashAmount
local player = game:GetService("Players").LocalPlayer

local function CashUpdate()
	player.PlayerGui.StatGUI.Frame.CashAmount.Text = "1000"
end

cashButton.MouseButton1Click:Connect(function()
	CashUpdate()
end)

I know that isn’t what you’re totally asking for but with the lack of information I’m just showing you how easy it is to talk script to script all local. This script is local the gui is local they don’t need fire server.

I do not want it to be local I need to change values from the server and send back the data to the GUI in the local script and what information do you need I will be more than happy to explain it more in depth I am not the greatest at explaining coding issues :/.

Why? … I need to know what you are doing. Isn’t this an update button?

Good practices mostly I could of finished this hours ago with local scripts but I am a CS Student in college so I am trying to make it the right way if I change data in a local script it will be way easier for people to give themselves stats than if I send the stats from the server :slight_smile: .