Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is the output not printing ">=" when I click the textbutton?

game.Players.PlayerAdded:Connect(function(player)
	print(player.Name.."has joined")
		local Cash = player:WaitForChild("leaderstats").Cash.Value
		if Cash then
		print("foundCash")
		script.Parent.MouseButton1Click:Connect(function()
	print("ClickedBuy")
	local price = script.Parent.Parent.Price.Value
		if Cash >= price then
			print(">=")
			end
		end)
	end
end)

2 comments

0

the code won't work if that's in a server script b/c the server doesn't listen to user input and it won't even detect when a new player joins if that code is in a local script

1

"the server doesn't listen to the user input" there is no user input... If this script is a server script then, it won't work because, the server cannot see any of the players gui's. use a localscript in startergui instead Gun..

2 answers

If this is a server script, you would have to put it into a local script, and at the beginning don't put "player" after function because you have game.Players.LocalPlayer

Edit: I just realized another error in your code. When you say:

local price = script.Parent.Parent.Price.Value

You should have said:

local price = script.Parent.Parent.Price

And instead of:

if Cash >= price then

You would do:

if Cash >= price.Value then

You would do the same thing with the cash variable, and in the end, it would look like this.

     local player = game.Players.LocalPlayer   
	local Cash = player:WaitForChild("leaderstats").Cash
        if Cash then
        print("foundCash")
        script.Parent.MouseButton1Click:Connect(function()
    print("ClickedBuy")
    local price = script.Parent.Parent.Price
        if Cash.Value >= price.Value then
            print(">=")
            end
        end)
    end

You can copy and paste if you want.

4 comments

0

no

0

its not printing>=

0

Okay, then I don't know what happened.

0

but is the statement abovr the print value true

You have to separate server code from GUI code. The server should (as you have there) be making sure that the player has enough money - but it shouldn't be directly responding to the player pressing a button. Your GUI code should use a RemoteEvent to inform the server of the player's wishes; the server should then confirm that the player can do that.

Resources:

Also note that server scripts don't run when placed in StarterGui - they can be in the workspace or ServerScriptService, see https://developer.roblox.com/api-reference/class/Script

This discussion is preserved as it was. New answers, comments, and votes are closed.