My script is not adding to players leaderstats, but it is resetting the value?

Me and @earthyviking92 (his main is @logbot22) are working on a game named Gym Simulator. That is aside from the point, I have a bench press in the game and here is the script:

local Tool = script.Parent

local Anim = Instance.new("Animation")

Anim.AnimationId = "rbxassetid://10556543684"

local track

script.Parent.Triggered:Connect(function(plr)

script.Parent.Parent:Sit(plr.Character.Humanoid)

track = plr.Character.Humanoid:LoadAnimation(Anim)

track.Priority = Enum.AnimationPriority.Action

track.Looped = false

plr.leaderstats.Stars.Value = plr.leaderstats.Stars.Value +3

track:Play()

end)

And here is a video of me getting “Stars” As me and @logbot22 like to call our leaderstats value and then it completely resetting.

The way I got “Stars” Before was I used the weight. The script inside the weight is:

local Tool = script.Parent
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://10546931590"
local track

Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if game.Players.LocalPlayer.Energy.Value >5 then
			game.Players.LocalPlayer.Energy.Value = game.Players.LocalPlayer.Energy.Value -5
			track = script.Parent.Parent.Humanoid:LoadAnimation(Anim)
		track.Priority = Enum.AnimationPriority.Action
		track.Looped = false
		game.Players.LocalPlayer.leaderstats.Stars.Value = game.Players.LocalPlayer.leaderstats.Stars.Value +5
		track:Play()
		wait(5)
		--	script.Parent.Parent.Humanoid.WalkSpeed = 16
		else
			game.Players.LocalPlayer.PlayerGui.Alert.TextLabel.Visible = true
			game.Players.LocalPlayer.PlayerGui.Alert.TextLabel.Text = "You have 0 energy. Please go to a cafe to get some coffee and fill up your energy!"
			
			wait(3)
			game.Players.LocalPlayer.PlayerGui.Alert.TextLabel.Visible = false
		end
	end)
end)

Tool.Unequipped:Connect(function()
	if track then
		track:Stop()
	end
end)

Any Feedback is appreciated! Thank you.

1 Like

From the second script, it looks like you’re adding stats to the player on a local script. Which means - these changes would only happen to that client. This won’t update/replicate to server.

1 Like

True, you should only change values on the server side, NEVER trust the client. Client should only be used to show the player something.

The issue might be because you are doing +3 instead of + 3.

I know that’s not the problem, I used to tutor people ROBLOX coding and other stuff and did that all the time. Had no effect, either than making it look a little messy.

1 Like

Well the issue here could be that it might be a local script changing the Value(?)

Yeah, anything with local is going to mess this up.

You do say a lot of stuff about the local player. Maybe you need to change the name of that? I don’t know much about datastore yet though.

Thank you, so much! I really appreciate it!

1 Like