I want the server to send a value picked up from a numbervalue to the client but I keep getting errors and don’t know how to resolve it.
SERVER SIDE SCRIPT, is placed inside a screengui button called “Collect”
local Parent = script.Parent
local REP = game.ReplicatedStorage
local Available = Parent.Parent.NumberImage.IncomeDisplay.Available.Value -- Value that needs to be sent
Parent.MouseButton1Click:Connect(function()
REP.MoneyTransfer:FireClient(Available)
Available.Value = 0
task.wait(2)
end)
CLIENT SIDE SCRIPT, is placed inside “StarterPlayerScripts”
local REP = game.ReplicatedStorage
local Player = game.Players.LocalPlayer
REP.MoneyTransfer.OnClientEvent:Connect(function(Available)
Player.leaderstats.Aureus.Value += Available
task.wait(1)
end)
change the remote event to a remote function, then on the client detect the click and invoke the server, then there you’ll get the value, but for future reference when you fire the client, the first value is the player to fire it to (and Available is not a player).
When you fired the Client, you didn’t put in a player variable, so it didn’t send the value to anybody.
(Also I wouldn’t change the leaderstats value inside the local script as it would do nothing)
In the first code block that you’ve mentioned, REP.MoneyTransfer:FireClient(Available) must be a player, you’re sending the “Available” value instead. It should be REP.MoneyTransfer:FireClient(Player, Available)
In order to get the player instance from the GUI button, you could change how your system works in a way where you detect the click from the client, fire a remote to the server, and do the variable change there as trusting the client(the user) with things such as in-game currency could be very risky because there wouldn’t be a way to validate the legitimacy.
I hope this could help - remember, changing most things on the client won’t replicate to the server or to other players, meaning the server wouldn’t know the value of “Available”, and so the rest of the players.
I’ve tried doing this now but the local script does not detect when the “Available” value has changed and keep printing 0 when pressing the button and debug.