Okay basically i'm just trying to make kind of a cookie clicker game.
I have a local script inside a button, which is inside a screen gui. The script has the following code inside it:
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 1
Basically this is supposed to give the player 1 more cash every time he clicks the button, which it does do that, but only the player who clicked it sees this, no one else does.
I'm assuming I have to use an event in order to make this work, however i'm not entirely sure how those work yet, and any help/explanations would be very appreciated!
Also, how do I organize my code in a way that people can understand? I have seen people get the numbers out beside but I don't know how to do that.
Hello, Alexanders1123, my name is TheOnlySmarts and I think I know the solution to your problem.
The reason why only the player who clicks sees it but others don't is because you're changing the Cash through the Client. Because this is inside of a TextButton, which is inside of StarterGui/PlayerGui, the game automatically registers it as a Client Script.
The client is the player who runs the script through their monitor. Which in shorter terms, means 'Local'.
However, if we were to change the Cash through the server, then the whole 'server' would see the Cash change.
But how would we do this?
Well, we will need the following...
Now that we have listed the following things we will need, we can now move on to scripting.
-- LocalScript ( Inside of TextButton ) local remoteEvent = game.ReplicatedStorage.RemoteEvent local value = game.Players.LocalPlayer.leaderstats.Cash script.Parent.MouseButton1Click:Connect(function() remoteEvent:FireServer("changeValue", value) end) -- Script ( Inside of ServerScriptService) local remoteEvent = game.ReplicatedStorage.RemoteEvent remoteEvent.OnServerEvent:Connect(function(plr, changeValue, value) value.Value = value.Value + 1 end)
I hope this has helped you, if it did, let me know and please upvote if you can ;)