Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to update leaderstats?????

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

1 comment

0

"why not working"

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.