The code is not working as intended

hey dude are those screenshots enough?

Sorry. I am have been very busy, and also I was trying to fix one of my old projects, and haven’t been on the devforum in a while. And yes, those are enough.

Are you trying to make something like this?

local function checkCoins()
    local plr = game.Players.LocalPlayer
    
    if plr.STATSHOLDERNAME.STATNAME.Value ~= 0 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.
        game.Players.PlayerGUI.tools_gui.tools_frame.ScrollingFrame:WaitForChild("buy all").Visible = true
    else
        game.Players.PlayerGUI.tools_gui.tools_frame.ScrollingFrame:WaitForChild("buy all").Visible = false
    end
end

checkCoins()

PlayerGUI is not a valid member of Players “Players”
and yes with a few changes if the coins’ value is greater than the tools’ cost then only it should be visible. I tried to make those changes.

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

	if plr.leaderstats.Coins.Value ~=0  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.
		game.Players.PlayerGUI.tools_gui.tools_frame:WaitForChild("canbuy").Visible = true
		game.Players.PlayerGui.tools_gui.tools_frame:WaitForChild("status").Text = "BUY"
		game.Players.PlayerGui.tools_gui.tools_frame:WaitForChild("cant_buy").Visible = false
	else
		game.Players.PlayerGUI.tools_gui.tools_frame:WaitForChild("can_buy").Visible = false
		game.Players.PlayerGUI.tools_gui.tools_frame:WaitForChild("status").Text = "CANT BUY!"
		game.Players.PlayerGUI.tools_gui.tools_frame:WaitForChild("cant_buy").Visible = false
	end
end

checkCoins()

I don’t know if you managed to fix the script but I’d recommend adding this to your code if you didn’t already.

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

So this’ll call the checkCains() function whenever your coins value changes.

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’