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

Regeneration part loses leaderstat points once regenerated?

Asked by 4 years ago

Timed regen script

model = game.Workspace.Part 


backup = model:clone()

while true do
    wait(60)

    model:remove()



    model = backup:clone()
    model.Parent = game.Workspace
    model:makeJoints()

end

Whenever I touch the part, it gives me the points, but when it regenerates, my points return to zero

Cash script

amnt = 5 
function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Money")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                end
            end
        end
        script.Parent:remove()
    end
end

script.Parent.Touched:connect(onTouched)

Leaderstats script

function Entered(player)
    wait()

    if player:findFirstChild("leaderstats") ~= nil then
        player.leaderstats:remove()
    end

    stats = Instance.new("IntValue")
    stats.Parent = player
    stats.Name = "leaderstats"

    money = Instance.new("IntValue")
    money.Parent = stats
    money.Name = "Money"
    money.Value = 0

end

game.Players.PlayerAdded:connect(Entered)

c = game.Players:GetChildren()
for i=1, #c do
    Entered(c[i])
end

Answer this question