The code is not working as intended

hey i added that lines after i sent that script and also now i dont have any errors in my output tab now idk why

Does the script work as intented now or it’s still broken?

its still broken. I debugged it too everything prints.

by changes i mean when the player has more or enough coins to buy a tool then the buy button will be visible

this is checking if the coins are NOT 0 and not above the price try something like this

local function checkCoins()
	local plr = game.Players.LocalPlayer

	if plr.leaderstats.Coins.Value >= price  then
		plr.PlayerGui.tools_gui.tools_frame:WaitForChild("canbuy").Visible = true
		plr.PlayerGui.tools_gui.tools_frame:WaitForChild("status").Text = "BUY"
		plr.PlayerGui.tools_gui.tools_frame:WaitForChild("cant_buy").Visible = false
	else
		plr.PlayerGui.tools_gui.tools_frame:WaitForChild("can_buy").Visible = false
		plr.PlayerGui.tools_gui.tools_frame:WaitForChild("status").Text = "CANT BUY!"
		plr.PlayerGui.tools_gui.tools_frame:WaitForChild("cant_buy").Visible = true
	end
end

checkCoins()
~= (not equal to)
>= (more than or equal to)
== (equal to)
<= (less or equal to)
< (less than)
> (more than)

also this needs to be a local script, thats either in the starter gui or the starter player

it still doesnt work :frowning:

local function checkCoins()
	local plr = game.Players.LocalPlayer
	local frame = game.Player.PlayerGUI.tools_gui.tools_frame
	local price = tonumber(frame.price.Text)
	if plr.leaderstats.Coins.Value >= price  then -- Replace STATSHOLDERNAME with the name of the item/folder the stat is in, then change STATNAME to the name of stat, e.g coins.
		frame:WaitForChild("canbuy").Visible = true
		frame:WaitForChild("status").Text = "BUY"
		frame:WaitForChild("cant_buy").Visible = false
	else
		frame:WaitForChild("can_buy").Visible = false
		frame:WaitForChild("status").Text = "CANT BUY!"
		frame:WaitForChild("cant_buy").Visible = false
	end
	plr.leaderstats.Coins:GetPropertyChangedSignal('Value'):Connect(function()
		checkCoins()
	end)
end

Its PlayerGui not PlayerGUI its case sensitive. And put the

outside of the function otherwise it wont work. I also see that you put game.Player.PlayerGUI this wont work. Try this:

local plr = game.Players.LocalPlayer

local function checkCoins()
	local frame = plr.PlayerGui.tools_gui.tools_frame
	local price = tonumber(frame.price.Text)
	if plr.leaderstats.Coins.Value >= price  then -- Replace STATSHOLDERNAME with the name of the item/folder the stat is in, then change STATNAME to the name of stat, e.g coins.
		frame:WaitForChild("canbuy").Visible = true
		frame:WaitForChild("status").Text = "BUY"
		frame:WaitForChild("cant_buy").Visible = false
	else
		frame:WaitForChild("can_buy").Visible = false
		frame:WaitForChild("status").Text = "CANT BUY!"
		frame:WaitForChild("cant_buy").Visible = true
	end
end

plr.leaderstats.Coins:GetPropertyChangedSignal('Value'):Connect(function()
	checkCoins()
end)

idk why but it still doesn’t work

Can you screenshot the hierarchy of your explorer (by this I mean screenshot the whole explorer)





where is the script you are doing this in and what is it called?

in startplayer and its called “localscriptbuy”

Okay, heres what should work:

  1. Put the Localscript inside of StarterGui.
  2. Inside of the local script put this code:
game.Players.LocalPlayer.leaderstats.Coins.Changed:Connect(function()
    local truecoins = game.ReplicatedStorage.REMOTE_FUNCTION_NAME:InvokeServer()
    local frame = script.Parent:FindFirstChild("tools_gui"):FindFirstChild("tools_frame")
    if (truecoins >= tonumber(frame.price.Text)) then
         frame.canbuy.Visible = true
         frame.status.Text = "BUY"
         frame:FindFirstChild("cant_buy").Visible = false
    else
         frame.canbuy.Visible = false
         frame.status.Text = "NOT ENOUGH COINS"
         frame:FindFirstChild("cant_buy").Visible = true
    end
end)
  1. Make a RemoteFunction inside of ReplicatedStorage named whatever you want, this will be used to get the leader stats data and the price from the server-side so that exploiters cant cheat to get the thing.
  2. Make a server script inside of ServerScriptService and put this in it:
game.ReplicatedStorage.REMOTE_FUNCTION_NAME.OnServerInvoke = function(plr)
    return plr.leaderstats.Coins.Value
end

This is the way to securely get the coins and show it. The other way you can do this if you just put the localscript in StarterPlayer.StarterPlayerScripts, but this is the better version of the script.

(the script doesnt work because its in starterplayer only and not in starterplayerscripts)

i got an error
Players.itzmerose_12.PlayerGui.feetus:1: attempt to index number with ‘Changed’

Is it .Coins.Changed or is it something else, since it should work if it is how i wrote it

No its supposed to be Coins.Changed i edited it after

it still doesnt work and there is no errors in the console/ output tab

hey i got an error
the error:
Players.itzmerose_12.PlayerGui.feetus:4: attempt to compare nil <= number

hey guys thank for your help i figured how to fix the code and its working

it works thank you for helping me :smiley: