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

Money giver not working?

Asked by 8 years ago

Once a player touches he or she is supposed to get XP. However it does not work

HELP!

script.Parent.Touched:connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local leaderstats = Hit.Parent:FindFirstChild("leaderstats")
        if leaderstats ~= nil then
                print("leaderstats found!")
                      local XP = leaderstats:FindFirstChild("XP") 
                    if XP ~= nil then
                                print("XP FOUND!")
                        Hit.Parent.leaderstats.XP.Value = Hit.Parent.leaderstats.XP.Value +5
                    end

        end
    end
end)

1 answer

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Leaderstats are typically inside of the Player object, but you kept referencing to the player's character!

script.Parent.Touched:connect(function(Hit)
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent) -- Checks if it is a player
    if player then
        local leaderstats = player:findFirstChild("leaderstats")
        if leaderstats then
            leaderstats:WaitForChild("XP").Value = leaderstats:WaitForChild("XP").Value + 5 -- I used WaitForChild to ensure no errors could arise, claiming it's not there
        end
    end
end)
Ad

Answer this question