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

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

Asked by 8 years ago

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

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
8 years ago

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

0
So, PlayerGui and StarterGui are the same thing. RobotChitti 167 — 8y
1
Not Exactly, A Player Gui is a Gui which goes to an Individual player, a Screen gui goes to all Players. KenzaXI 166 — 8y
1
Placing the Gui in the StarterGui will make nobody see it. Discern 1007 — 8y
0
Oh okay RobotChitti 167 — 8y
Ad

Answer this question