script.Parent.MouseButton1Click:Connect(function() game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + game.Players.LocalPlayer.leaderstats.RewardR.Value end)
in roblox studio works but in client dont works.. ? what is the problem ? Thanks!?
Script
instead of a LocalScript
. Script
s 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 -- example script.Parent.Activated:Connect(function(inputObject) GiveCash:FireServer() end)
ServerScriptService
wait() local ReplicatedStorage = game:GetService('ReplicatedStorage') local GiveCash = ReplicatedStorage.GiveCash GiveCash.OnServerEvent:Connect(function(player) -- player who fired remote local amt = player.leaderstats.RewardsR player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + amt.Value end)
LocalScript
to listen for it being clicked, or just anything that the GUI will do, be handled on the client.