I am making a store screenGUI. I am trying to get the Player from a MouseButton1Click on a textButton so that I can make sure it has enough points and then subtract those points. Here is the code: (Top is what I have now bottom is how I want to get the points from leaderboard)
local sP = script.Parent
–Text colors
local yellow = Color3.fromRGB(245, 184, 41)
local grey = Color3.fromRGB(145, 145, 145)
–Lock, Unlock and Own item
local function updateItem(item, itemID, status)
local parentFrame = item
if status == "Owned" or status == "Locked" then
parentFrame.BuyButton.TextColor3 = grey
parentFrame.Info.TextColor3 = grey
parentFrame.Title.TextColor3 = grey
parentFrame.Pic.Image = parentFrame.Pic.Unsaturated.Value
if status == "Owned" then
parentFrame.BuyButton.Text = "Owned"
parentFrame.isOwned.Value = true
else
parentFrame.BuyButton.Text = "Locked"
parentFrame.isLocked.Value = true
end
else
parentFrame.BuyButton.TextColor3 = yellow
parentFrame.Info.TextColor3 = yellow
parentFrame.Title.TextColor3 = yellow
parentFrame.Pic.Image = parentFrame.Pic.Saturated.Value
parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
parentFrame.isLocked.Value = false
end
end
local function doPurchase(button)
local parentFrame = button.Parent
local isOwned = parentFrame.isOwned.Value
local isLocked = parentFrame.isLocked.Value
if isOwned ~= true or isLocked ~= true then
updateItem(parentFrame, parentFrame.ItemID.Value, "Owned")
--Unlocks upgrade
--if parentFrame.isItem.Value == true then
--print(parentFrame.ItemID.Value + 4 .. " item unlocked")
--end
end
end
for i, button in ipairs (sP.Store:GetDescendants()) do
if button.ClassName == 'TextButton' and button.Name == "BuyButton" then
button.MouseButton1Click:Connect(function() -- Give it an anonymous function
doPurchase(button) -- Fire the function with the button parameter
end)
end
end
–Below is how I would like to get the points from leaderstats once I have the player
local player = game:GetService(“Players”):GetPlayerFromCharacter(Something idk)
local leaderstats = player.leaderstats
local pointStat = leaderstats and leaderstats:FindFirstChild(“Points”)
if pointStat.Value >= Cost then
pointStat.Value = pointStat.Value - Cost
end