Trouble with interaction with blocks and ScreenGui in Roblox

711 views Asked by At

I need help with the "ScreenGui" object in Roblox. I am trying to write code that will allow a gui to pop up when a player clicks on a block through the gui will not show. The script calling the function to make the gui pop up is under workspace and the script creating the gui is in the startergui folder.

This is the script that is calling the other one:

script.Parent.ClickDetector.MouseClick:connect(shared["ShowGui"]);

The script to be called is:

shared["ShowGui"] = function()
    print("Hello World");
    sg = Instance.new("ScreenGui", game.StarterGui);
    fr = Instance.new("Frame", sg);
    fr.Size = UDim2.new(0,200,0,60);
    fr.Position = UDim2.new(0, 0, 0.5, -60);
    fr.Visible = true;
    fr.Active = true;
    fr.BackgroundColor3 = Color3.new(1, 0, 0);
end 

The function is being called as when I click the block, the console is outputting "Hello World", so I know that it is being called.

I also tested the code without it being a function and the gui shows up as it should.

So now I'm just trying to figure out why it won't create the gui when the script is being called as a function.

2

There are 2 answers

0
ZombieSpy On

First i find the seperation of the scripts ilogical. Second if you put a gui in the StarterGui it will ONLY be seen after you respawn.

All gui objects in the StarterGui is relicated to players' PlayerGui once they respawn.

try to put this script in the brick instead:

script.Parent.ClickDetector.MouseClick:connect(function(PlayerThatClicked)
    Screen = Instance.new("ScreenGui", PlayerThatClicked.PlayerGui)
    Frame = Instance.new("Frame", Screen )
    Frame.Size = UDim2.new(0,200,0,60)
    Frame.Position = UDim2.new(0, 0, 0.5, -60)
end)

I am currently not able to test run the code, so it might not work as i expect.

0
codingPotato On

First what I would do is in StarterGui have a ScreenGui then under that a Frame. In the frame you can put some text buttons and text boxes. I would put the script in the frame so all you need to do to get to the gui in the script is

local frame = script.Parent
frame.BackgroundTransparency = 1

Then you carry on with the script.