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)
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
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.
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
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)
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 :/.
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 .