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