Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 5 years ago
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!?

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). hellmatic 1523 — 5y
0
server script? User#21499 0 — 5y
0
server script is a normal script, that runs on the server User#23365 30 — 5y
0
yea im using normal script. and this script inside the button. User#21499 0 — 5y
View all comments (2 more)
0
its dont works.. User#21499 0 — 5y
0
but in studio its works.. User#21499 0 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
hmm wait ill try it User#21499 0 — 5y
0
i dont get it.. can you say me that on easier way? User#21499 0 — 5y
0
i didnt get that what u mean by that GiveCash.OnServerEvent:Connect(function(player) User#21499 0 — 5y
0
OnServerEvent is a server-side event, when the remote is fired, it will run any code on the server. User#19524 175 — 5y
View all comments (6 more)
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? User#21499 0 — 5y
0
The code containing the OnServerEvent should be a server script in ServerScriptService. User#19524 175 — 5y
0
kk ill try. User#21499 0 — 5y
0
ReplicatedStorage.GiveCash i see this on script so does this means that i need to add something? User#21499 0 — 5y
0
It is a RemoteEvent. User#19524 175 — 5y
0
omg its works buddy User#21499 0 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

Thanks alot incapaz

Answer this question