I'm trying to make it so when you click a button it adds +1 to the leaderboard

I put a script inside of a textbutton and its suppose to make the train move and also add 1 to the players stats. But so far it only moves the train and doesn’t add anything to the player’s stats. This is the script I’ve been working on so far, please let me know if you encounter any errors. I tried using remote events but I have no idea how to use it. I tried reading this about Remote Events but I still have no idea how to use it.

Here is the script:

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)
```S
2 Likes

First off, why are you editting this on the client, thats a bad idea!, and second you have to add .leaderstats to your thing like this.

game.Players.LocalPlayer.leaderstats.TimesRanOver.Value += 1

But please, use remote event security so that way exploiters can’t easily hack your game.

I changed it to a normal script. The problem about remote events is I have no idea how to use it.

I used remote events but it still did the same thing, it wouldn’t add anything to the leaderstats. I’ll try relooking at it today to see the problem.

Try using the player argument to change it like this.

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

script.Parent:Destroy()

move()
Give(plr)
function Give(plr)
game.Players[plr].leaderstats.TimesRanOver.Value += 1
end
2 Likes