✓ Accepted answer
###This is because you used a Script instead of a LocalScript. Scripts do not run in PlayerGui, they probably did because you used Play Solo. In Studio's Play Solo mode, there is no separation of the server and client. This is why your Script worked. It doesn't in a real game. A fix would be to use a LocalScript, but that change only shows to you. To combat this, use a RemoteEvent.
wait()
local Player = game:GetService('Players').LocalPlayer
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local GiveCash = ReplicatedStorage.GiveCash
script.Parent.Activated:Connect(function(inputObject)
GiveCash:FireServer()
end)
###Server script, in ServerScriptService
wait()
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local GiveCash = ReplicatedStorage.GiveCash
GiveCash.OnServerEvent:Connect(function(player)
local amt = player.leaderstats.RewardsR
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + amt.Value
end)
###Edit:
###When you want to make a script that powers a GUI, always use a LocalScript to listen for it being clicked, or just anything that the GUI will do, be handled on the client.
6 comments
Use a server script to change the player's cash. Using a local script will only show change to the client (for ex it shows you have 100 but for another player you have 0).
server script?
server script is a normal script, that runs on the server
yea im using normal script. and this script inside the button.
its dont works..
but in studio its works..