Touch part to GUI

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? When you touch a part, a GUI pops up.

  2. What is the issue? It does not work properly.

  3. What solutions have you tried so far? I have looked at multiple forum posts and none of them seem to suit me.

Here is the script:

local Brick = script.Parent.SCIParts.Touch


Brick.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
		game.Players.LocalPlayer.PlayerGui.LoadingGUI.Background.Visible = true
	end
end)

Thanks.

local Brick = script.Parent.SCIParts.Touch


Brick.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
		game.Player:GetPlayerFromCharacter(other.Parent).PlayerGui.LoadingGUI.Background.Visible = true
	end
end)
i.LoadingGUI.Background.Visible = true
	end
end)
1 Like

The script must be a local script to get the local player, place it in StarterGui or something and redefine the Brick variable.

I am cloning the GUI into StarterGui with a separate script though.

Does not work. There are no errors unfortunately.

I would appreciate it if you could send me some more code to work with here and your explorer tab.

Try using remote events. What worked for me was to have the server check for collisions, and then fire an event. When the client detects the event, make the GUI visible.

Remote events shouldn’t be necessary as the client can check for collisions.

1 Like

Sure, ill tell you everything.

So this is the script that brings the Gui up on collision with the part. It is a local script in the model:

local Brick = script.Parent.SCIParts.Touch


Brick.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
		game.Player:GetPlayerFromCharacter(other.Parent).PlayerGui.LoadingGUI.Background.Visible = true
	end
end)

This script is the just a regular serverscript located in the model that clones the Loading gui:

script.Parent:WaitForChild("LoadingGUI"):Clone().Parent = game.StarterGui

script.Parent.LoadingGUI:Destroy()

Then this is my explorer tab:

1 Like

No need to clone the GUI, you can keep it in StarterGui keeping Visible = false.

local Brick = workspace.BLAHBLAH.BLAHBLAH -- redirect this to your brick


Brick.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
		game.Players.LocalPlayer.PlayerGui.LoadingGUI.Background.Visible = true
	end
end)

No you do not understand. I want the GUI to be cloned. I am making a Self Check-In for people and I want it to be as easy as possible.

What you could do is add this script to ServerScriptService, then add the GUI inside the script. Then, once the Part in Workspace is touched, then you can :Clone() the GUI to the client’s PlayerGui.

If you want the Gui to be cloned, simply remove the code mentioned above and make sure Visible = true. In a server script, you can simply clone and remove.

I did what you said and this is my script:

local Brick = script.Parent.SCIParts.Touch


Brick.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
		script.Parent:WaitForChild("LoadingGUI"):Clone().Parent = game.StarterGui
	end
end)

But it does not seem to be cloning.

The reason is you have to do this:

local Brick = script.Parent.SCIParts.Touch


Brick.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
		script.Parent:WaitForChild("LoadingGUI"):Clone().Parent = game.Players:GetPlayerFromCharacter(other.Parent) --not starterGui then everyone see's it.
	end
end)

That still would not work as you’re parenting the gui to the player, not to PlayerGui.

Were gonna use the above code but alter it a little bit

Brick.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(other.Parent) 
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
		GuiClone.Parent = Player.PlayerGui
	end
end)

Anyways I have no idea if this works but here you go.

I changed the script to a regular server script because the local script would not clone the GUI. But when I clone it into StarterGUI with the visibility on, it never appeared. It would always be blank. So when I tried to make the GUI visible with a line of code, I kept getting the same error. I do not know what to do.

There is no need of checking for humanoid, just check for the player. Don’t use WaitForChild() on the server script since the server is authoritative.

Also, you shouldn’t post scripts if you aren’t positive if it’s going to work or not.

Brick.Touched:Connect(function(other)
    local Player = game.Players:GetPlayerFromCharacter(other.Parent)
 
	if Player then
        local Gui = script.Parent:WaitForChild("LoadingGUI")
        local GuiClone = Gui:Clone()
		GuiClone.Parent = Player.PlayerGui
	end
end)

StarterGui get’s cloned to PlayerGui when a player joins. Therefore, you need to get the player who touched the part and then clone the Gui to the PlayerGui using remote events.

Here’s a demonstration.

script.Parent.Touched:Connect(function(hit)
     local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        if player then
          game.ReplicatedStorage.RemoteEvent:FireClient(player) -- pass the arg for the player who touched it
     end
end)

Then, you can use OnClientEvent and clone it to the player. Always handle UI on the client for immediate response.