Script Working In Studio Yet Not Game (Unsolved)

Sup, I have a script here that allows you to change your shirt, but if you press this textbutton it goes back to your default shirt. The script works, however, it only works if the player hasn’t reset. When the player resets, it doesn’t work, with no errors being outputted.

Here’s my local script:

local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("rev")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
if not player:HasAppearanceLoaded() then player.CharacterAppearanceLoaded:Wait() end

task.wait()
local clothing = {}
local shirt = character:FindFirstChildOfClass("Shirt")
local pants = character:FindFirstChildOfClass("Pants")
local tShirt = character:FindFirstChildOfClass("ShirtGraphic")
if shirt then clothing.Shirt = shirt.ShirtTemplate end
if pants then clothing.Pants = pants.PantsTemplate end
if tShirt then clothing.TShirt = tShirt.Graphic end

local textButton = script.Parent

local function onButtonClicked()
	remote:FireServer(clothing)
end

textButton.MouseButton1Click:Connect(onButtonClicked)

Server script:

local function onRemoteFired(player, clothing, types)
	
	if not player.Parent then return end
	local character = player.Character
	if not character then return end
	if clothing.Shirt then character.Shirt.ShirtTemplate = clothing.Shirt end
 
end

remote2.OnServerEvent:Connect(onRemoteFired)

Any help would be Appreciated.

Any errors in the server console? (F9, Server) Shows the output but in game.

Ah, I messed something up in my post, the script works, however, it only works if the player hasn’t reset. When the player resets, it doesn’t work, with no errors being outputted.

Is ResetOnSpawn (Properties of the GUI) on or off?

Your gui has a reset on respawn property. Turn it on. In the explorer, click the gui in which the text button is, and turn on the “Reset on Respawn”.

1 Like

Thats what was causing it. I turned that off, joined the game, and now it works fine. Thanks.