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

I was wondering how to make this?

I am making a script so the first person who touches the button each round gets a point. Whenever i try it a red line goes under and breaks the script. Here is the script

if game.Players:GetPlayerFromCharacter(hit.Parent) then game.Players:GetPlayerFromCharacter.Leaderstats.Points.Value = game.Players:GetPlayerFromCharacter.Leaderstats.Points.Value + 1 end

2 comments

0

Is the Leaderstats and points value in the character? Or just in the Player. Try moving the values in Player so it wont get messed up online.

0

How?

1 answer

I assume this is in a touched event?

Anyways, on lines 2 and 3 you are using GetPlayerFromCharacter(), but failing to provide the character argument. You are basically trying to get the player from the character of nothingness. Try this:

if game.Players:GetPlayerFromCharacter(hit.Parent) then
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	plr:WaitForChild("Leaderstats"):WaitForChild("Points").Value = plr.Leaderstats.Points.Value + 1
end

I also used WaitForChild() in case Leaderstats is not fully loaded when the code runs.

Note that the leaderstats will probably not show up on the in-game leaderboard because you named it 'Leaderstats' instead of 'leaderstats'. Also note that since PlayerAdded events don't fire in PlaySolo mode, there will likely not be any leaderstats if you're trying to test it in PlaySolo.

Because of the nature of Touched event, you may want to look into adding a debounce.

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