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

How can insert a gui into someones screen?

Asked by
NRCme 0
8 years ago

So i'm working on a game and i need the game to give the person a gui when they step on a part so far i have

local brick = game.Workspace.Brick

function onTouch(part)

end 

brick.Touched:connect(onTouch)

So, as you see I have no idea howto insert a gui into someones screen. Please help!

2 answers

Log in to vote
0
Answered by 8 years ago

There are many ways you could do this.

First of all, you could already have the GUI inside the StarterGui and make it visible when you touch.

Or you could clone the GUI from ServerStorage. Let's do this.

First, insert your GUI inside ServerStorage.

Then, let's change define a few variables

local serverstorage = game:GetService("ServerStorage") --Gets "ServerStorage," which is what we're storing your gui in until we need it.
local gui = serverstorage:WaitForChild("ScreenGui") --I'm assuming that's the name of your GUI.

--Make sure this script is inside the brick, by the way.

script.Parent.Touched:connect(function(hit) --If the part is touched, fire this function. Takes argument "hit"
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Gets the player.
local playergui = player:WaitForChild("PlayerGui") --Gets the client's PlayerGui.

local guiclone = gui:Clone() --Clones the gui from ServerStorage

guiclone.Parent = playergui --Sets the parent of the cloned gui to the player's client PlayerGui

end) --ends function

I hope this helped!

Ad
Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

First, you need to create the GUI. Store the GUI somewhere, then when the Player touches the part, clone and paste it in their PlayerGui

You have the touch function and connection down, now you need to create the GUI and put it in the Brick.

local brick = game.Workspace.Brick
local Gui = brick.Gui -- Or where ever the GUI is

function onTouch(part)
if part.Parent then
local Player = game:GetService('Players'):FindFirstChild(part.Parent.Name)
if not Player then return end -- Check if thats a player
Gui:clone().Parent = Player.PlayerGui -- The cloning and pasting
end
end 

brick.Touched:connect(onTouch)
0
how can i access the gui from another script if its moving around NRCme 0 — 8y

Answer this question