How would I get this script to replace a gui?

So I have a script that brings up a gui when you touch a brick, but there are lots of bricks and I need to delete and old gui when you step on a new brick. The problem with this is that it just seems to always delete the gui. I tried a bunch of waits and stuff too but it didn’t work.
Here’s the part of the script with the gui stuff-
also this is a server script
I would also like to mention the script’s problem is because of it destroys the gui once it’s cloned.

	player.PlayerGui.morph_gui:Destroy()
	script.morph_gui:Clone().Parent = player.PlayerGui
1 Like

Is this from server or client?

This is a serverrrrrrr script.

1 Like

Can you show more of the script?

2 Likes

There isn’t really anything else that refers to the gui, but here
also yes I know this script has errors, I’m making this for a friend and they don’t really ruin the script so.


Speed = 16 -- This is the character's speed! 16 is normal walkspeed.

----------------

debounce = false

function onTouch(hit)

if game.Players:FindFirstChild(hit.Parent.Name) ~= nil and debounce == false then

local player = game.Players:FindFirstChild(hit.Parent.Name)

local c = player.Character:GetChildren()

debounce = true

for i=1, #c do

if (c[i].className == "Hat") or c[i].Name == "Character" then

c[i]:Destroy()

end

end

player.Character.Torso.Transparency = 1

player.Character:FindFirstChild("Left Arm").Transparency = 1

player.Character:FindFirstChild("Left Leg").Transparency = 1

player.Character:FindFirstChild("Right Arm").Transparency = 1

player.Character:FindFirstChild("Right Leg").Transparency = 1

player.Character.Humanoid.WalkSpeed = (Speed) -- You can change how fast players walk as this character!

local hide = Instance.new("SpecialMesh")

hide.MeshType = "FileMesh"

MeshId = ""

hide.Parent = player.Character.Head

local p = script.Parent.Parent:FindFirstChild("Character"):clone()

p.Parent = player.Character

p.CFrame = CFrame.new(player.Character.Torso.Position)

p.Anchored = false

local Y = Instance.new("Weld")

Y.Part0 = player.Character.Torso

Y.Part1 = p

Y.Parent = Y.Part0

if player.PlayerGui:FindFirstChild("morph_gui") then

player.PlayerGui.morph_gui:Destroy()

script.morph_gui:Clone().Parent = player.PlayerGui

itemlist = script.Parent:FindFirstChild("StartTools"):GetChildren()

if #itemlist ~= 0 then

for i= 1, #itemlist do

local itemc = itemlist[i]:clone()

itemc.Parent = player.Backpack

end

end

wait(1)

debounce = false

end

end

end

script.Parent.Touched:connect(onTouch)
1 Like

You shouldn’t be accessing player gui from the server, try using a remote event from server that tells the client to destroy the gui and add the new gui.

Also, please indent your code :sweat:

Where is this script and your new gui located?

1 Like

The script is in a brick and the gui is a child of the script.

I did that but it didn’t do anything?
The script worked just fine before without the destroy thing.

I think you need to parent the cloned gui to the Player.PlayerGui.ScreenGui

The gui clones to playergui just fine.

So the gui gets cloned perfectly but then you cant see it?

yes, the problem is the script ends up destroyed the gui that’s cloned

The gui must be a child of the ScreenGui for you to be able to see it

Except that’s not the problem-

The script will just remove the Morph GUI and add it back again?
What’s the point with deleting it in the first place?
@reminiscynt

1 Like

there’s other bricks that can give you the gui with the same name and I need to get rid of that if you’ve gotten one.

Still don’t have any solution.

not trying to liven the post at all

Change the name of the GUI, since you probably mess things up.