Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I'm trying to make it so when you click a button it adds +1 to the leaderboard, see anything wrong?

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

0

Is there an error message? Also the value is changed only from the client from this script.

0

What do you mean the value can only be changed by the client of this script?

0

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.

2 answers

✓ Accepted answer

You can only destroy script.Parent after you execute the script, or you will just destroy the script and it will stop running

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)

move()
Give()
script.Parent:Destroy()

end)

Also, this should be a server script, try using Remote Events

Here Is The Script I Haven't Tested It So idk If It Will Work But Here

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.leaderstats.Value = game.Players.LocalPlayer.TimesRanOver.leaderstats.Value +1
end




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

script.Parent:Destroy()

move()
Give()


end)

If It Works Than Please Accept My Answer

1 comment

0

Doesn't work, sorry.

This discussion is preserved as it was. New answers, comments, and votes are closed.