Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Give intvalue to another intvalue in roblox studio works in client not? Help

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!?

6 comments

0

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

0

server script?

0

server script is a normal script, that runs on the server

0

yea im using normal script. and this script inside the button.

0

its dont works..

0

but in studio its works..

2 answers

✓ 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 -- example 

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) -- player who fired remote 
    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.

10 comments

0

hmm wait ill try it

0

i dont get it.. can you say me that on easier way?

0

i didnt get that what u mean by that GiveCash.OnServerEvent:Connect(function(player)

0

OnServerEvent is a server-side event, when the remote is fired, it will run any code on the server.

0

okay. so that first script u added here i need create localscript and add it in button and then 2rd script to serverscriptservice RIGHT?

0

The code containing the OnServerEvent should be a server script in ServerScriptService.

0

kk ill try.

0

ReplicatedStorage.GiveCash i see this on script so does this means that i need to add something?

0

It is a RemoteEvent.

0

omg its works buddy

This discussion is preserved as it was. New answers, comments, and votes are closed.