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

How do you increase the leaderboard?

Asked by 5 years ago

I have made a leaderboard, but I don't know how to increase it. I want to make it so when you collide with a part, it destroys the part and gives you the value this is my code so far: script in serverscriptservice

local function onPlayerJoin(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player


    local gold = Instance.new("IntValue")
    gold.Name = "Gold"
    gold.Value = 0
    gold.Parent = leaderstats

end

game.Players.PlayerAdded:Connect(onPlayerJoin)

script inside of part:

script.parent.Touched:connect(function(Player)
        script.parent:destroy() 
        Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value + 1
    end)

when I run it, it says leaderstats is not a valid member of Part What do I do?

1 answer

Log in to vote
1
Answered by
blockmask 374 Moderation Voter
5 years ago
Edited 5 years ago

Ok, first of all, the parameter for the Touched event is the object that hit it, not the player you'd have to check if the thing that touched it has a humanoid, and if it does, then it's either an npc or a player's character. Now, you have to check if it's an actual player, so you use Players:GetPlayerFromCharacter() to get the actual player.

local reward = 20

script.Parent.Touched:Connect(function(hitObject)
    local humanoid = hitObject.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(hitObject.Parent)
        if player then
            if player:FindFirstChild("leaderstats") then
                player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + reward
            end
        end
    end
    script.Parent:Destroy()
end)

Also, :connect, and :destroy() are deprecated

0
put the link into (). Miniller 562 — 5y
0
remove is deprecated, destroy is not. :Destroy() is the correct usage. DinozCreates 1070 — 5y
0
Thank you! Noonekirby 162 — 5y
0
@blockmask, you have a typo on line 3, it should be script.Parent, not script.parent saSlol2436 716 — 5y
View all comments (2 more)
0
Oh, right blockmask 374 — 5y
0
Fixed, thank you guys blockmask 374 — 5y
Ad

Answer this question