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

How do i make an actual working "reset obby" that resets the leaderboard for the player who clicked?

Asked by
Idleino 11
4 years ago

Hi. I tried to make a "reset obby" gui that had inside a local script that contained this script:

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
    player.leaderstats.Stage.Value = 1
end)

I also tried to use a normal script but it didnt work at all. the script did work with localscript and the leaderboard showed 1 when i clicked on it but when i tried to respawn i was still on stage 2 it didnt teleport me to stage 1. How can i fix this? thank you :D

1
That's because LocalPlayer is only a property that localscripts can use. ScuffedAI 435 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Your LocalScript cannot access leaderstats because it is on the client side. The client cannot access leaderstats; only the server can. This is why we use a RemoteEvent. I will show you how it works. First, insert a RemoteEvent in ReplicatedStorage. Then keep your LocalScript in your GUI, but insert a regular Script in ServerScriptService.

LocalScript

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer(player) -- LocalScript uses RemoteEvent to tell the server script to do its job now
end)

Script in ServerScriptService

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) -- The server script is currently executing its code because it was fired by the RemoteEvent from the LocalScript
player.leaderstats.Stage.Value = 1
end)

Hope this helps!

0
Thank you so much!!!!!! i tried for about half an hour to figure it out, you are the best!!! Idleino 11 — 4y
0
The Client can actually acces the leaderstats. But any changes made on the Client is only visible for the Client. So that's why we do it on the server Spjureeedd 385 — 4y
0
That's my bad. I didn't think about it that way as well because that is the case sometimes on these questions. Thank you for correcting me, Spjureeedd! AntiWorldliness 868 — 4y
Ad
Log in to vote
0
Answered by
DesertusX 435 Moderation Voter
4 years ago

Maybe you should get the player from the function instead. Use a server script (normal script).

script.Parent.MouseButton1Click:connect(function(player)
    player.leaderstats.Stage.Value = 1
end)

Don't forget to accept the answer if I helped!

Answer this question