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

How do I grab a player's point value using a button?

I am making a button that when you click on it, it subtracts the cost from your points and opens the egg so you get a pet, like in simulator games. My issue is that I am struggling to grab the players point value. Points are NOT displayed on the leaderstats, they are stored in the Player.

This is not a local script

script.Parent.MouseButton1Down:Connect(function()
	
	local plr = game.Players.LocalPlayer
	
	if plr.Points.Value >= cost then
		
		plr.Points.Value = plr.Points.Value - cost
		
		local pet = petModule.chooseRandomPet()
		
		print(pet.Name.." selected")
		end
end)

4 comments

0

you cant get the localplayer from a normal script

0

Do this function on a local script, then send a remote event to a script, and send the points value with it.

0

Where are the points stored? I'm assuming they are stored in the player?

0

The points are stored in the player

1 answer

✓ Accepted answer

You cannot get LocalPlayer in a server script. To find it, replace line 3 with this:

local plr = script.Parent --Continue adding parents until plr is equal to the player

Example: script > button > frame > screengui

local plr = script.Parent.Parent.Parent.Parent.Parent --All guis go in playerGui, which is in the player

I hope this answers your question

4 comments

0

NOTE: your "petmodule" needs to be defined if it hasn't already. I don't see the require() function being called

0

sorry, yes the require function is being called, I just cut it off. This method of finding the player is a little confusing. I should mention that the script if located somewhere in the StarterGui folder.

0

Yes, you would add .Parent for each Parent of the script until StarterGui. Then you would add one more. I hope that makes some sense.

0

Thank you so much!

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