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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
you cant get the localplayer from a normal script Pupppy44 671 — 4y
0
Do this function on a local script, then send a remote event to a script, and send the points value with it. Nootian 184 — 4y
0
Where are the points stored? I'm assuming they are stored in the player? User#30567 0 — 4y
0
The points are stored in the player Buthter 6 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

0
NOTE: your "petmodule" needs to be defined if it hasn't already. I don't see the require() function being called IAmNotTheReal_MePipe 418 — 4y
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. Buthter 6 — 4y
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. IAmNotTheReal_MePipe 418 — 4y
0
Thank you so much! Buthter 6 — 4y
Ad

Answer this question