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.
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)
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.