Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to reset leaderbored with a part?

Asked by 3 years ago

I need Help on a script that will reset your leaderbored stats When touching a part

game.Players.PlayerAdded:connect(function(p)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    stats.Parent = p

    local money = Instance.new("IntValue")
    money.Name = "Coins" 
    money.Value = 50
    money.Parent = stats
end)

That's my leader bored script.

0
Right, and where's the code that demonstrates you tried? Ziffixture 6913 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Add a script on the part, then put this code:

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local money = Instance.new("IntValue")
    money.Name = "Coins" 
    money.Value = 50
    money.Parent = leaderstats
end)


script.Parent.Touched:Connect(function(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
    local player = game.Players:FindFirstChild(otherPart.Parent.Name)
    player.leaderstats.Coins.Value = 0 --resets points
    print(player.Name.. " reseted points to 0!") -- you can remove this
end)

Tell me when there's a problem.

Ad

Answer this question