#learning for the first time: gui

1 messages · Page 1 of 1 (latest)

twin sky
#

Just trying to make a gui, a button that opens a menu with 3 more buttons, 1 to kill all, explode all and fling all. It should cost robux to do each. I currently already have a working invite button.

The issue is I am met with 2 errors:
Infinite yield possible on 'Players.theLord8.PlayerGui:WaitForChild("TrollButton")' - Studio
and
Script 'Players.theLord8.PlayerGui.ScreenGui.LocalScript', Line 7 - Studio - LocalScript:7

In testing, I can open the menu, but clicking on any of the kill/explode/fling buttons doesnt give the robux prompt.
I added the image of my explorer page of how i ordered everything.

It has 2 localscipts and there is 1 serverscript
Here they are:
LocalScript for button to open menu called opentroll

local Frame = SGui:WaitForChild("MenuFrame")
local Button = SGui:WaitForChild("TrollButton")

local KillButton = Frame:WaitForChild("KillButton")
local ExplodeButton = Frame:WaitForChild("ExplodeButton")
local FlingButton = Frame:WaitForChild("FlingButton")

Button.MouseButton1Up:Connect(function()
    Frame.Visible = not Frame.Visible
    print("MenuFrame visible: " .. tostring(Frame.Visible))  -- Debugging line to confirm visibility toggle
end)


-- Add functionality to each action button (optional for testing)
KillButton.MouseButton1Click:Connect(function()
    print("Kill action triggered!")
    -- Implement the action here (e.g., kill all players)
end)

ExplodeButton.MouseButton1Click:Connect(function()
    print("Explode action triggered!")
    -- Implement the action here (e.g., explode all players)
end)

FlingButton.MouseButton1Click:Connect(function()
    print("Fling action triggered!")
    -- Implement the action here (e.g., fling all players)
end)```

I will send the other 2 scripts in message below
#

Then the localscript with the roblox developer product asset id's to buy them

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local screenGui = script.Parent.Parent  -- Assuming the script is inside the Frame
local openButton = screenGui:WaitForChild("TrollButton")
local menuFrame = script.Parent:WaitForChild("MenuFrame")

local killButton = menuFrame:WaitForChild("KillButton")
local explodeButton = menuFrame:WaitForChild("ExplodeButton")
local flingButton = menuFrame:WaitForChild("FlingButton")

-- Replace these with your actual Dev Product IDs
local DEV_PRODUCTS = {
    Kill = 3273656636,
    Explode = 3273657002,
    Fling = 3273657610
}

openButton.MouseButton1Click:Connect(function()
    print("TrollButton clicked!")
    menuFrame.Visible = not menuFrame.Visible
end)


local function promptPurchase(action)
    local productId = DEV_PRODUCTS[action]
    print("Prompting purchase for: " .. action .. " with product ID: " .. tostring(productId))
    if productId then
        MarketplaceService:PromptProductPurchase(player, productId)
    end
end


killButton.MouseButton1Click:Connect(function() promptPurchase("Kill") end)
explodeButton.MouseButton1Click:Connect(function() promptPurchase("Explode") end)
flingButton.MouseButton1Click:Connect(function() promptPurchase("Fling") end)

-- Handle purchase
MarketplaceService.PromptProductPurchaseFinished:Connect(function(p, id, wasPurchased)
    if p == player and wasPurchased then
        for action, pid in pairs(DEV_PRODUCTS) do
            if pid == id then
                ReplicatedStorage.PurchaseEvent:FireServer(action)
            end
        end
    end
end)

#

Then the ServerScript


local purchaseEvent = ReplicatedStorage:WaitForChild("PurchaseEvent")

purchaseEvent.OnServerEvent:Connect(function(player, action)
    for _, target in pairs(game.Players:GetPlayers()) do
        if target ~= player then
            local character = target.Character
            if character then
                if action == "Kill" then
                    character:BreakJoints()
                elseif action == "Explode" then
                    local explosion = Instance.new("Explosion")
                    explosion.Position = character:GetPivot().Position
                    explosion.BlastRadius = 10
                    explosion.Parent = workspace
                elseif action == "Fling" then
                    local hrp = character:FindFirstChild("HumanoidRootPart")
                    if hrp then
                        hrp.Velocity = Vector3.new(math.random(-100,100), 150, math.random(-100,100))
                    end
                end
            end
        end
    end
end)

Please help figure out whats wrong.

pine dawn
#

u forgot

#

to

#

add the screengui

#

as trollbutton is in screengui

twin sky
pine dawn
#

EVERYTHING

#

in startergui

#

gets cloned to playergui

#

that includes ScreenGuis

twin sky
#

oh ye ye

pine dawn
#

and your path to TrollButton is StarterGui.ScreenGui.TrollButton

#

Not StarterGui.TrollButton

twin sky
#

why does it skip screengui, i have it under screengui

pine dawn
#

..?

#

wait a sec

#

i havent seen code

#

just the error

twin sky
#

like screengui is under startergui

pine dawn
#

hold up

twin sky
#

oh

pine dawn
#

u just

#

used too many .Parent

#

as your script is in startergui -> screengui

#

so script.Parent is screengui

#

and script.Parent.Parent is startergui

#

and u used 2x Parent

twin sky
#

is that bad

pine dawn
#

one too much

#

your local ScreenGui isnt set to screengui

twin sky
#

as in i dont need screengui or

pine dawn
#

its set to starterGui/PlayerGui

twin sky
plain stratusBOT
#

studio** You are now Level 1! **studio

pine dawn
#

🙏

twin sky
#

ok so local screenGui = script.Parent.Parent -- Assuming the script is inside the Frame becomes just
local screenGui = script.Parent -- Assuming the script is inside the Frame

pine dawn
#

yes

twin sky
#

ill try it soon

#

is there a way to see history of changes after closing and opening the place

pine dawn
#

but thats about it

#

i believe

twin sky
#

mkay, ill be a bit making it

#

okay

#

the TrollButton to open the menu no longer opens the menu

#

but when i had the menu visible i did get robux purchase prompt

#

which ZIndex should be 2