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

How Do You Make It so If You Have Enough Currency a GUI Appears, If Not Another GUI Appears?

Asked by 3 years ago

I have a script that is supposed to show a gui if you have enough currency, "are you sure you want to purchase this product?" and if not "not enough currency." But it doesn't work. Instead it doesn't open the any of the guis when a text button is clicked. (Here is my code, it is a local script)

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvents.SaveAllTools.OnServerEvent:Connect(function(player)
        if player.leaderstats.Bacon.Value >= 150 then
        script.Parent.Parent.Parent.SaveAllToolsAndWeaponsCheck.Visible = true
        else
            script.Parent.Parent.Parent.NotEnoughBacon.Visible = true
        end
    end)
end)

1 answer

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

I think there's some anomalies there. The button click is supposed to fire the "Save all tools" event. Which is supposed to be located in a local script inside the button, or inside the GUI. (I'm not sure if the location is a must, but i usually place it there.) So, i suggest if you wanna follow my advice, scrap that script you have there, delete it. And follow my way.

Oh, before i continue, I just want to let you know that this method is not very efficient, therefore you might want to wait for someone to come up with a better solution. But if you're in a hurry, and don't mind writing some scripts and adding a few Remote events, you can follow this.

So, you create a local script in the BUY button, and in that local script you only have to write:

player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(fucntion()
    game.ReplicatedStorage.RemoteEvents.SaveAllTools:FireServer(player)
end)

Then, the server script will recieve the signal from the local script, and then.

game.ReplicatedStorage.RemoteEvents.SaveAllTools.OnServerEvent:Connect(function(player)
    if player.leaderstats.Bacon.Value >= 150 then
        game.ReplicatedStorage.RemoteEvents.MAKEANEWREMOTEEVENT:FireClient(true)
    else
                game.ReplicatedStorage.RemoteEvents.MAKEANEWREMOTEEVENT:FireClient(false)
    end
end)

Now i forgot to mention, you have to create another Remote event to handle the gui, be sure to replace "MAKEANEWREMOTEEVENT" with the remote event name, i'm sure you already know lol. And also make a local script to receive the signal, place it inside the where the "Buy" Gui is, name it whatever, but i personally love to name it "PopupHandler"

After you created a local script in the buy gui. You can do the scripting, it's something along the lines of:

game.ReplicatedStorage.RemoteEvents.MAKEANEWREMOTEEVENT.OnClientEvent:Connect(function(state) --Sorry if it doesn't work as i literally wrote this on the top of my head
    if state == true then
        script.Parent.Parent.Parent.SaveAllToolsAndWeaponsCheck.Visible = true
    else
        script.Parent.Parent.Parent.NotEnoughBacon.Visible = true
    end
end)

And that should work. I hope. If you have any trouble, add some debugging print here and there, and, just let me know. I'll try what i can do to help. Good luck.

1
Tysm, it worked. MrSarp_shoot 37 — 3y
0
Glad it worked iMazariuz 36 — 2y
Ad

Answer this question