Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
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)
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 User#23252 26 — 4y
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.. greatneil80 2647 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
no GunzerkingBeast21 -4 — 4y
0
its not printing>= GunzerkingBeast21 -4 — 4y
0
Okay, then I don't know what happened. FrostedFlakes67 71 — 4y
0
but is the statement abovr the print value true User#28169 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question