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
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)
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?