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

How come the ScreenGUI and ImageLabel didn't pop up after onClicked?

I made a model and added the ClickDetector in one of the part in there that can be clickable. Well, I put the position and size and the id for it to make the picture pop up after I click it. But apparently it didn't work. This is the script:

local song1 = game.Workspace.BoxCD.song1
local gui = game.StarterGui
local screen = Instance.new("ScreenGui", gui)
local image = Instance.new("ImageLabel", screen)
touch = false

function onClicked()
	if not touch then
		touch = true
		image.Position = UDim2.new({0, 300}, {0, 100})
		image.Size = UDim2.new({0, 450}, {0, 400})
		image.Image = "rbxassetid://238387775"
		touch = false
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I hope what I asked and explain is understandable.

1 answer

✓ Accepted answer

When using UDim2 in a script, the arguments do not need {}'s like it shows in properties. UDim2.new(XScale, XOffset, YScale, YOffset) are the correct arguments.

Also, you need to place GUIs in the player's PlayerGui if you want them to be able to see the image. MouseClick has a parameter for the player who clicked the ClickDetector. Place the GUI in their PlayerGui.

local song1 = game.Workspace.BoxCD.song1
local gui = game.StarterGui
local screen = Instance.new("ScreenGui", gui)
local image = Instance.new("ImageLabel", screen)
touch = false

function onClicked(clicker) --clicker is the argument for the player who clicked the button
    if not touch then
        touch = true
        local screen = Instance.new("ScreenGui", clicker.PlayerGui) --Place the Gui inside their PlayerGui in order for them to see it.
        local image = Instance.new("ImageLabel", screen)
        image.Position = UDim2.new(0, 300, 0, 100) 
        image.Size = UDim2.new(0, 450, 0, 400)
        image.Image = "rbxassetid://238387775"
        touch = false
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

If I helped you, be sure to accept my answer! :D

4 comments

0

So, PlayerGui and StarterGui are the same thing.

1

Not Exactly, A Player Gui is a Gui which goes to an Individual player, a Screen gui goes to all Players.

1

Placing the Gui in the StarterGui will make nobody see it.

0

Oh okay

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