Still have questions? Join our Discord server and get real time help.
0

How do I make a changed leaderstat appear for everyone?

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:

script.Parent.MouseButton1Click:Connect(function()

wait(0.1)

end)

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.

0
Assuming your game is FE, this would be exploitable. You need to create and set the leaderstat values in the server and have the server change it. The server will replicate the value to other players, so there is no need for remote events. If you use GUIs for clicking, you have to use Remote Events to communicate with the server. Otherwise you can use ClickDetectors on the server. PhantomVisual 338 — 9d
0
Okay, thanks. I'll try to see what I can do. Alexanders1123 12 — 9d

0

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

• RemoteEvent - place in ReplicatedStorage
• Variables in our script

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

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

Thanks, TheOnlySmarts.

0
Why are you passing a parameter that you never use? RobloxWhizYT 1852 — 9d
0
The "changeValue" parameter, not the player parameter. RobloxWhizYT 1852 — 9d
0
Works great, thank you! Just a small question, what does the changeValue mean in lines 7 and 14? Alexanders1123 12 — 8d
0
The changeValue parameter is just an easier way of identifying the event and also making it easier to access the event. TheOnlySmarts 155 — 8d
0
And also, no problem Alexanders, I hope you have fun when scripting ;D TheOnlySmarts 155 — 8d