I put a local script inside of a textbutton and its suppose to make the train move and also add 1 to the players stats. But it only moves the train and doesn't add anything to the player's stats.
local Train = game.Workspace.Train
function move()
for v = 0,1,.05 do
Train:SetPrimaryPartCFrame(Train:GetPrimaryPartCFrame() * CFrame.new(0,0, -v))
wait()
end
while wait() do
Train:SetPrimaryPartCFrame(Train:GetPrimaryPartCFrame() * CFrame.new(0,0,0 + -1.9))
end
end
function Give()
game.Players.LocalPlayer.TimesRanOver.Value = game.Players.LocalPlayer.TimesRanOver.Value +1
end
script.Parent.MouseButton1Click:Connect(function(plr)
script.Parent:Destroy()
move()
Give()
end)

3 comments
Is there an error message? Also the value is changed only from the client from this script.
What do you mean the value can only be changed by the client of this script?
The leaderstats dont replicate to the server ,only the client. The way to fix this is to either put this code inside a normal script or using remote events to fire a server script.