Sometimes the GUI breaks and freezes
I’ve tried to add wait for childs and debugs but i still can’t figure it out.
This is where it is in explorer
This is the ERROR i am getting when it breaks
This is what shows up when i first join for comparision
This is the SCRIPT that’s called SCRIPT
local Button = script.Parent:WaitForChild("ClickDetector")
local Client = script:WaitForChild("WigClient")
local Function = Instance.new("RemoteFunction", script)
Function.Name = "WigFunction"
Client:WaitForChild("Object").Value = Function
local RemoteFunctions = {}
local Wigs = {}
local WigStorage = nil
--[[Settings below]]-------------------------------------------
local InsWigs = true
local WigIDs = {4583631312,4583633769,4583634861,4583636120,4614014869,4614052139,4614057112,4614068352,4614073817,4655291821,4655293681,4655295493,4655298199,4655308743,4655310658,4655311694,4655312936,4677541474,4677546410,4677549901,4677552405,4677555065,4684541306,4686442477,4686468061,4686475004,4686477789,4686481577,4686484947,4686487752,4686491057,4686493251,4686495857,4686498006,4686500443,4686502731} --Put the IDs in here id,id,id,[...]
---------------------------------------------------------------
function Weld(Hat)
local Parts = {}
for _,Part in pairs (Hat:GetChildren()) do
local Class = Part.ClassName
if Class == "Part" or Class == "WedgePart" or Class == "UnionOperation" then
table.insert(Parts,Part)
if Part.Name ~= "Handle" then
local Weld = Instance.new("Weld",Part)
Weld.Part0 = Part
Weld.Part1 = Hat.Handle
Weld.C0 = Weld.Part0.CFrame:inverse()
Weld.C1 = Weld.Part1.CFrame:inverse()
end
end
wait()
end
for _,Part in pairs (Parts) do
Part.Anchored = false
end
end
function RemoteFunctions.Close(Player)
Player.Character:FindFirstChild(Client.Name):Destroy()
Player.PlayerGui:WaitForChild("WigGui"):Destroy()
end
function RemoteFunctions.GetWigs(Player)
return Wigs
end
function RemoteFunctions.GetWigInstance(Player, Position)
if Player:FindFirstChild("WigStorage") ~= nil then
Player:FindFirstChild("WigStorage"):Destroy()
end
local WigStorage = Instance.new("Folder", Player)
WigStorage.Name = "WigStorage"
local Wig = Wigs[Position][1]:Clone()
Wig.Parent = WigStorage
return Wig
end
function RemoteFunctions.WearWig(Player, Int, Color)
for _,Hat in pairs (Player.Character:GetChildren()) do
if Hat.ClassName == "Hat" then
Hat:Destroy()
end
wait()
end
local Wig = Wigs[Int][1]:Clone()
Wig.Parent = Player.Character
Wig.Part.Mesh.VertexColor = Vector3.new(Color.r, Color.g, Color.b)
--Weld(Wig)
return Wig.Handle
end
Button.MouseClick:connect(function(Player)
if Player.Character then
if Player.Character:FindFirstChild(Client.Name) == nil then
local NewClient = Client:Clone()
NewClient.Parent = Player.Character
NewClient.Disabled = false
end
end
end)
function Function.OnServerInvoke(Player,F,A1,A2,A3)
return RemoteFunctions[F](Player,A1,A2,A3)
end
if InsWigs == true then
WigStorage = Instance.new("Model",game.ServerStorage)
WigStorage.Name = "WigStorage"
for _,ID in pairs (WigIDs) do
local bool,arg = pcall(function()
local Wig = game:GetService("InsertService"):LoadAsset(ID):GetChildren()[1]
Wig.Parent = WigStorage
Weld(Wig)
table.insert(Wigs,{[1] = Wig, [2] = ID})
end)
if bool == false then print(arg) end
wait()
end
else
WigStorage = game.ServerStorage:WaitForChild("WigStorage")
for _,Wig in pairs (WigStorage:GetChildren()) do
local bool,arg = pcall(function()
table.insert(Wigs,{[1] = Wig, [2] = Wig["AssetID"].Value})
Weld(Wig)
end)
if bool == false then print(arg) end
wait()
end
end
Below is the SCRIPT called WIG CLIENT
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local Server = script:WaitForChild("Object").Value
local Gui = script:WaitForChild("WigGui"):Clone()
Gui.Parent = Player:WaitForChild("PlayerGui")
local Frame = Gui:WaitForChild("Frame")
local Temp = Frame:WaitForChild("Temp")
local Main = Frame:WaitForChild("Main")
local Color = Frame:WaitForChild("Color")
local PreviewColor = Color:WaitForChild("Preview")
local ViewportFrame = Main.ViewportFrame
local Wigs = Server:InvokeServer("GetWigs") --{[1] = WigInstance, [2] = WigID}
local ButtonFunctions = {}
local Position = 0
local setIndexActive, CurrentWig, ClearVPF
function ButtonFunctions.Close()
Gui:Destroy()
if Player:FindFirstChild("WigStorage") ~= nil then
Player:FindFirstChild("WigStorage"):Destroy()
end
Server:InvokeServer("Close")
end
function ButtonFunctions.Wear()
local Wig = Server:InvokeServer("WearWig", Position, PreviewColor.BackgroundColor3)
Gui:Destroy()
if Player:FindFirstChild("WigStorage") ~= nil then
Player:FindFirstChild("WigStorage"):Destroy()
Gui:Destroy()
end
Server:InvokeServer("Close")
end
function ButtonFunctions.Right()
if Position + 1 <= #Wigs then
Position = Position + 1
elseif Position + 1 > #Wigs then
Position = 1
end
local ID = Wigs[Position][2]
local Data = game:GetService('MarketplaceService'):GetProductInfo(ID,0)
Main.Header.Text = Data.Name
Main.AssetImage.Image = 'https://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId='..tostring(ID)
end
function ButtonFunctions.Left()
if Position - 1 >= 1 then
Position = Position - 1
elseif Position - 1 < 1 then
Position = #Wigs
end
local ID = Wigs[Position][2]
local Data = game:GetService('MarketplaceService'):GetProductInfo(ID,0)
Main.Header.Text = Data.Name
Main.AssetImage.Image = 'https://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId='..tostring(ID)
end
for _,Button in pairs (Main:GetChildren()) do
if Button.ClassName == "ImageButton" or Button.ClassName == "TextButton" then
Button.MouseButton1Click:connect(function()
ButtonFunctions[Button.Name]()
end)
end
end
local camera = Instance.new("Camera")
camera.FieldOfView = 70
ViewportFrame.CurrentCamera = camera
function setIndexActive(Model)
Model.Parent = Main.AssetImage
end
function ClearVPF()
Main.AssetImage:ClearAllChildren()
end
coroutine.resume(coroutine.create(function()
while true do
wait(0.1)
if Main.AssetImage:FindFirstChild("Model") then
if Main.AssetImage.Model:FindFirstChild("Hat") then
local Color = PreviewColor.BackgroundColor3
Main.AssetImage.Model.Hat.Part.Mesh.VertexColor = Vector3.new(Color.r, Color.g, Color.b)
end
end
end
end))
Below is the SCRIPT called Colour Main
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local TargetFrame = script.Parent:WaitForChild("Frame").Color
local rgb = TargetFrame:WaitForChild("RGB")
local value = TargetFrame:WaitForChild("Value")
local preview = TargetFrame:WaitForChild("Preview", 5)
local selectedColor = Color3.fromHSV(1, 1, 1)
local colorData = {
1,
1,
1
}
local mouse1down = false
function setColor(hue, sat, val)
colorData = {
hue or colorData[1],
sat or colorData[2],
val or colorData[3]
}
selectedColor = Color3.fromHSV(colorData[1], colorData[2], colorData[3])
preview.BackgroundColor3 = selectedColor
value.ImageColor3 = Color3.fromHSV(colorData[1], colorData[2], 1)
end
function inBounds(frame)
local x, y = Mouse.X - frame.AbsolutePosition.X, Mouse.Y - frame.AbsolutePosition.Y
local maxX, maxY = frame.AbsoluteSize.X, frame.AbsoluteSize.Y
if x >= 0 and y >= 0 and x <= maxX and y <= maxY then
return x / maxX, y / maxY
end
end
function updateRGB()
if mouse1Down then
local x, y = inBounds(rgb)
if x and y then
rgb:WaitForChild("Marker").Position = UDim2.new(x, 0, y, 0)
setColor(1 - x, 1 - y)
end
local x, y = inBounds(value)
if x and y then
value:WaitForChild("Marker").Position = UDim2.new(0.5, 0, y, 0)
setColor(nil, nil, 1 - y)
end
end
end
Mouse.Move:connect(updateRGB)
Mouse.Button1Down:connect(function()
mouse1Down = true
end)
Mouse.Button1Up:connect(function()
mouse1Down = false
end)
ANY help is helpful