Why does this not work?

local part = script.Parent
local gui = game.StarterGui.MorphGUI.MainFrame

part.Touched:Connect(function(part)
	gui.Visible = true
	gui:Clone()

end)

image
image

2 Likes

I think you’re making the gui in starter gui visible and then just cloning it without a destination.

1 Like

How should I clone it to the PlayerGUI?

1 Like
local playerService = game:GetService("Players")
local part = script.Parent
local gui = game.StarterGui.MorphGUI.MainFrame

part.Touched:Connect(function(part)
	local guiClone = gui:Clone()
        guiClone.Visible = true
        local player = playerService:GetPlayerFromCharacter(part.Parent)
        guiClone.Parent = player.PlayerGui
end)
1 Like

I’m sorry I accidentally sent it early so I edited it a bit, didn’t test it in studio, but I think this should work.

1 Like

I just realised this is a horrible way to do it, I’ll rewrite the code one sec

1 Like

well first you need to check if the thing that touched “part” is a player

local Part = script.Parent
local GUI = game.StarterGui.MorphGUI.MainFrame

Part.Touched:Connect(function(Hit) 
  -- Hit would be the player's foot or leg
  local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
  local PlayerGui = Player:WaitForChild("PlayerGui")
  -- Check if the player already has the gui
  if PlayerGui:FindFirstChild(GUI.Name) then return end

  local GUIClone = GUI:Clone()
  GUIClone.Enabled = true
  GUIClone.Parent = PlayerGui
end)
1 Like

Yeah, also my original script would clone it infinitely

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.