How do i deduct the required points?

The issue I’m facing is that my shop script isn’t correctly reaching the StinkPoints value inside leaderstats, so the game doesn’t know whether the player has enough points to buy the pet. I need to define what requiredpoints are which is the amount of points you need to buy a pet when you click the textbutton(buybutton) which is the parent of the script. each player has stinkpoints stored in their leaderstats so the stinkpoints don’t reset when they leave.


local buybutton = script.Parent
local player = game.Players.localplayer
local stinkPoints = player:FindFirstChild("leaderstats"):FindFirstChild("StinkPoints")
print("Player's stink points:", stinkPoints.Value)
local requiredpoints = 100
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
	local stinkPoints = leaderstats:FindFirstChild("StinkPoints")
	if stinkPoints then
		if stinkPoints.Value >= requiredPoints then
			print("You have enough Stink Points to buy this!")
			-- Deduct points and grant the pet/item
			stinkPoints.Value = stinkPoints.Value - requiredPoints 
		else
			print("Not enough Stink Points! You need at least " .. requiredPoints .. ".")
		end
	end
end

One, I’m pretty sure you’re defining LocalPlayer wrong. It’s case sensitive I believe .

Two you cannot subtract leader stats from a local script and expect it to work server-wide. You need a remote event to fire to a server script and subtract the points from there.

Three make sure you have a leader stats script and that your Stink Value shows up in game on a real Roblox generated leaderboard

1 Like