I’m trying to make a difficulty chart game, and there are buttons that are meant to bring you back / forward a stage when pressed (if you have them unlocked): to avoid cheating, when a button is pressed it fires an event to the server depending on what button was pressed and then changing their current stage leaderstat and teleporting them to that stage.
Currently, it teleports them to that stage, but does not change their leaderstat. It is being changed on the server, meaning that could not be the problem.
Using print() to test shows that the RemoteEvent is being recieved and the requirements are met, but it does not change the player’s leaderstat.
It seems to be being changed, and then being changed back quickly as printing the stage value after the event returns what the value should be, but it won’t save.
(The arguments the function is checking for are the types of button presses)
game:GetService("ReplicatedStorage").SkipClick.OnServerEvent:Connect(function(player, action)
local stage = player:WaitForChild("leaderstats").Stage.Value
print(player:WaitForChild("leaderstats").Stage.Value)
local max = player:WaitForChild("extra").max.Value
if action == "LO" then
if stage > 1 then
stage = stage - 1
print(stage)
end
elseif action == "LP" then
if stage > 11 then
stage = stage - 10
end
elseif action == "RO" then
if (max - stage) > 0 then
stage = stage + 10
end
elseif action == "RP" then
if (max - stage) > 9 then
stage = stage + 10
end
else
warn("Unauthorised Action from ".. player.Name ..": " .. action)
end
local stagePosition = game.Workspace.Stages:FindFirstChild(tostring(stage))
player.Character:MoveTo(stagePosition.Position)
end)
youre saving the stage value to the stage variable and only changing the value inside of that script.
game:GetService("ReplicatedStorage").SkipClick.OnServerEvent:Connect(function(player, action)
local stage = player:WaitForChild("leaderstats").Stage
print(player:WaitForChild("leaderstats").Stage.Value)
local max = player:WaitForChild("extra").max.Value
if action == "LO" then
if stage.Value > 1 then
stage.Value -= 1
print(stage.Value)
end
elseif action == "LP" then
if stage.Value > 11 then
stage.Value -= 10
end
elseif action == "RO" then
if (max - stage.Value) > 0 then
stage.Value += 10
end
elseif action == "RP" then
if (max - stage.Value) > 9 then
stage.Value += 10
end
else
warn("Unauthorised Action from ".. player.Name ..": " .. action)
end
local stagePosition = game.Workspace.Stages:FindFirstChild(tostring(stage.Value))
player.Character:MoveTo(stagePosition.Position)
end)