You can write your topic however you want, but you need to answer these questions:
When using a command, the UI loads perfectly fine and I’m able to select a uniform.
However, after resetting my character, using the same command no longer loads the UI.
I’ve tried other similar solutions on the devforum, disabled ResetOnSpawn for the UI, as well as ChatGPT, but to no avail.
The script is a child of a UI, which is inside StarterGUI.
repeat task.wait(1) until game:IsLoaded()
--//Services
local Players = game:GetService("Players")
local RPS = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
--//Variables
local Events = RPS:WaitForChild("Events")
--plr
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
char.Archivable = true
local MainFrame = script.Parent:WaitForChild("Main")
local originalshirt, originalpants = char:FindFirstChildOfClass("Shirt"), char:FindFirstChildOfClass("Pants")
--VPF setup
local CharacterPreview = MainFrame["Character Preview"].ViewportFrame
local MouseInDisplay, HoldInDisplay = true, false
local currentX
local VPFcam = Instance.new("Camera")
VPFcam.Parent = CharacterPreview
VPFcam.CFrame = CFrame.new(0,0,0)
CharacterPreview.CurrentCamera = VPFcam
local ClonedChar = char:Clone()
ClonedChar.Parent = CharacterPreview.WorldModel
ClonedChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,2,-6.5),Vector3.new(0,0,0)))
local LastMaxZoom = plr.CameraMaxZoomDistance -- save the current settings
local LastMinZoom = plr.CameraMinZoomDistance -- ^
local ScrollDisabled = false
--Uniforms
local ScrollingFrame = MainFrame.Buttons.ScrollingFrame
local conns = {}
--Wearing
local WearButton = MainFrame.WearButton
local selectedUniform, selectedshirtid, selectedpantsid
--//Funcs
local function ToggleMainFrame()
if MainFrame.Visible == false then -- enable
MainFrame.Visible = true
TweenService:Create(MainFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = UDim2.new(0.5,0,0.5,0)}):Play()
else -- disable
TweenService:Create(MainFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = UDim2.new(0.5,0,-0.5,0)}):Play()
task.wait(0.3)
MainFrame.Visible = false
end
end
local function removeAllConnections()
for i, conn in conns do
conn:Disconnect()
end
conns = {}
end
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if MouseInDisplay == true then
end
HoldInDisplay = true
currentX = nil
end
end
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
HoldInDisplay = false
end
end
local function mouseMoved(X,Y)
if HoldInDisplay == false then return end
if currentX then ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,((X-currentX)*.025),0) end
currentX = X
end
local function wheelForward()
ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,2,0)
end
local function wheelBackward()
ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,-2,0)
end
local function onUniformClick(shirtid, pantsid, name)
local shirt : Shirt = ClonedChar:FindFirstChildOfClass("Shirt") or Instance.new("Shirt"); shirt.Parent = ClonedChar
local pants : Pants = ClonedChar:FindFirstChildOfClass("Pants") or Instance.new("Pants"); pants.Parent = ClonedChar
shirt.ShirtTemplate = "rbxassetid://"..shirtid
pants.PantsTemplate = "rbxassetid://"..pantsid
selectedUniform = name
WearButton.Text = "Wear ".. name
end
local function wearUniform()
if selectedUniform then
--equip on server
Events.WearUniform:FireServer(selectedUniform)
--tween
TweenService:Create(MainFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = UDim2.new(0.8,0,0.5,0)}):Play()
task.wait(2.3)
TweenService:Create(MainFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = UDim2.new(0.5,0,0.5,0)}):Play()
end
end
local function addAllUniforms()
local Uniforms = RPS:WaitForChild("Uniforms")
local Template = script.Template
for i, uniform : ModuleScript in pairs(Uniforms:GetChildren()) do
local newButton = Template:Clone()
newButton.Parent = ScrollingFrame
newButton.Name = uniform.Name
newButton.Text = uniform.Name
local module = require(uniform)
local shirtid = module.shirtid
local pantsid = module.pantsid
if uniform.Name == "Default" then
shirtid = char:FindFirstChildOfClass("Shirt").ShirtTemplate or ""
pantsid = char:FindFirstChildOfClass("Pants").PantsTemplate or ""
end
conns[#conns + 1] = newButton.MouseButton1Down:Connect(function()
onUniformClick(shirtid, pantsid, newButton.Name)
end)
end
end
function EnableScroll(val) -- simple on/off function for the zoomies
local currentZoom = (workspace.CurrentCamera.CoordinateFrame.p - plr.Character.Head.Position).magnitude
if val == true then -- Scroll is active
plr.CameraMaxZoomDistance = LastMaxZoom
plr.CameraMinZoomDistance = LastMinZoom
else -- scroll is inactive
plr.CameraMaxZoomDistance = currentZoom
plr.CameraMinZoomDistance = currentZoom
end
end
--//Events
--Turning
UserInputService.InputBegan:Connect(inputBegan)
UserInputService.InputEnded:Connect(inputEnded)
CharacterPreview.MouseWheelForward:Connect(wheelForward)
CharacterPreview.MouseWheelBackward:Connect(wheelBackward)
CharacterPreview.MouseMoved:Connect(mouseMoved)
CharacterPreview.MouseEnter:Connect(function()
MouseInDisplay = true
EnableScroll(false)
end)
CharacterPreview.MouseLeave:Connect(function()
MouseInDisplay = false
EnableScroll(true)
end)
--wearing
WearButton.MouseButton1Down:Connect(wearUniform)
MainFrame.close.MouseButton1Down:Connect(ToggleMainFrame)
--initialize
addAllUniforms()
--Toggle Visibility
Events.OpenUniforms.OnClientEvent:Connect(function()
ToggleMainFrame()
end)
This is the current script I’m using.