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

How to update leaderstats????? [closed]

Asked by 3 years ago

Im making an undertale game i neeed it to increase your LOVE by 5 when you touch sans. heres the code. function onTouched(hit) LOVE = LOVE + 5 end script.Parent.Touched:connect(onTouched) why not working

0
"why not working" WideSteal321 773 — 3y

Closed as Not Constructive by JesseSong

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

The problem is that you're just creating and then changing a value named 'LOVE', and not changing the one in the leaderboard.

To change a player's score on the leaderboard you'll first need to "get" the player object. Then we can play around with the values inside. Conveniently there's a function that allows us to get the player object if we know the character, and this is perfect since we can easily get the character when using the Touched event.

function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then --Make sure that a player (or NPC) is triggering the event
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- "Get" the player object
        if player then -- Make sure that a player activated the event and not an NPC
            player.leaderstats.LOVE = player.leaderstats.LOVE + 5 -- change the "LOVE" variable
        end
    end
end
script.Parent.Touched:Connect(onTouched)
Ad