Morph Button Issue

Hello there, so what I am trying to achieve is when you press the “ReturnButton” you turn into the "Gorilla Bouncer morph which is a complete rig/humanoid and is supposedly functional. Keep in mind I have used AI to assist me with this endeavor, so that’s why everything looks so messy. But to the issue that I am having currently… Everything was functioning as it was supposed to the morph would equipped, however after I had died it would not revert back to the orginial character and show the error down below. But basically it is look for archiable property, and I am not sure where it is trying to look at for it. If anyone can help me and let me know where I go from here on out I would be very appreciative. Thank you!

Lua Script:

– Button click script for morphing
local button = script.Parent
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local players = game:GetService(“Players”)
local workspace = game.Workspace

– Configuration
local morphFolderPath = {“Morphs”, “Gorillas”, “JungleGorillas”}
local morphName = “Gorilla Bouncer”
local requiredEvoStone = 25
local requiredLevel = 5
local requiredWins = 1
local checkForValueIdentifier = false

– Paths
local noPressImageLabel = button:FindFirstChild(“NoPress”)

– Function to find “ValueIdentifier” IntValue in the workspace
local function findValueIdentifier()
for _, descendant in pairs(workspace:GetDescendants()) do
if descendant:IsA(“IntValue”) and descendant.Name == “GorillaBuster” then
print(“Found GorillaBuster in workspace.”)
return true
end
end
print(“No GorillaBuster found in workspace.”)
return false
end

– Function to check if player meets the required leaderstats
local function checkLeaderstats(player)
local leaderstats = player:FindFirstChild(“leaderstats”)
if not leaderstats then
print(“Leaderstats not found for player:”, player.Name)
return false
end

local evoStone = leaderstats:FindFirstChild("Evo. Stone")
local level = leaderstats:FindFirstChild("Level")
local wins = leaderstats:FindFirstChild("Wins")

if not evoStone or evoStone.Value < requiredEvoStone then
	return false
end
if not level or level.Value < requiredLevel then
	return false
end
if not wins or wins.Value < requiredWins then
	return false
end

return true

end

– Function to update NoPress visibility and button Selectable state
local function updateButtonState(player)
local leaderstats = player:FindFirstChild(“leaderstats”)
if not leaderstats then
print(“Leaderstats not found for player:”, player.Name)
button.Selectable = false
if noPressImageLabel then
noPressImageLabel.Visible = true
end
return
end

local evoStone = leaderstats:FindFirstChild("Evo. Stone")
local level = leaderstats:FindFirstChild("Level")
local wins = leaderstats:FindFirstChild("Wins")

-- Check if the player meets all requirements
if evoStone and evoStone.Value >= requiredEvoStone and 
	level and level.Value >= requiredLevel and 
	wins and wins.Value >= requiredWins then
	print(player.Name .. " meets the requirements for morphing.")
	button.Selectable = true
	if noPressImageLabel then
		noPressImageLabel.Visible = false
	end
else
	print(player.Name .. " does not meet the requirements for morphing.")
	button.Selectable = false
	if noPressImageLabel then
		noPressImageLabel.Visible = true
	end
end

end

– Continuous check for button state
game:GetService(“RunService”).Stepped:Connect(function()
local player = players.LocalPlayer
if player then
updateButtonState(player)
end
end)

– Function to clone the original character for reverting
local function cloneOriginalCharacter(character)
if character and character.PrimaryPart then
local clonedCharacter = character:Clone()
clonedCharacter.Archivable = true – Ensure the character can be cloned
print(“Successfully cloned the original character.”)
return clonedCharacter
else
print(“Error: Character or PrimaryPart is nil. Cannot clone original character.”)
return nil
end
end

– Function to morph the player
local function morphPlayer(player)
print(“Checking leaderstats for player: " … player.Name)
if not checkLeaderstats(player) then
print(player.Name … " does not meet the requirements to morph.”)
return false
end

if checkForValueIdentifier then
	print("Checking for ValueIdentifier...")
	if not findValueIdentifier() then
		print("Cannot morph: No ValueIdentifier found.")
		return false
	end
end

local morphFolder = replicatedStorage
for _, folderName in ipairs(morphFolderPath) do
	morphFolder = morphFolder:FindFirstChild(folderName)
	if not morphFolder then
		print("Morph folder path is incorrect! Missing folder: " .. folderName)
		return false
	end
end

local morphModel = morphFolder:FindFirstChild(morphName)
if not morphModel then
	print("Morph model not found: " .. morphName)
	return false
end

print("Morphing player into: " .. morphName)

local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local spawnPosition = humanoidRootPart and humanoidRootPart.CFrame

-- Clone the original character for reverting
local originalCharacter = cloneOriginalCharacter(character)
if not originalCharacter then
	print("Failed to clone the original character. Morphing process aborted.")
	return false
end

-- Destroy the current character and replace with the morph
character:Destroy()

local newMorph = morphModel:Clone()
newMorph.Parent = workspace
if spawnPosition then
	newMorph:SetPrimaryPartCFrame(spawnPosition)
end

-- Ensure all parts of the morph are not anchored
for _, part in pairs(newMorph:GetDescendants()) do
	if part:IsA("BasePart") then
		part.Anchored = false
	end
end

-- Assign the new morph as the player's character
player.Character = newMorph

local humanoid = newMorph:FindFirstChildOfClass("Humanoid")
if humanoid then
	humanoid.AutoRotate = true
	humanoid.PlatformStand = false -- Ensure the humanoid can move freely
	game:GetService("Workspace").CurrentCamera.CameraSubject = humanoid

	humanoid.Died:Connect(function()
		wait(1)
		print(player.Name .. " has died, reverting to original character.")

		-- Revert to original character if available
		if player and originalCharacter and originalCharacter.PrimaryPart then
			print("Reverting " .. player.Name .. " to original character.")

			if player.Character then
				player.Character:Destroy()
			end

			-- Restore original character
			player.Character = originalCharacter
			originalCharacter.Parent = workspace
			originalCharacter:SetPrimaryPartCFrame(newMorph.PrimaryPart.CFrame)
		else
			print("Failed to revert player: originalCharacter or player is nil.")
		end
	end)
else
	print("Humanoid not found in the morph.")
	return false
end

-- Deduct Evo. Stones
local leaderstats = player:FindFirstChild("leaderstats")
local evoStone = leaderstats and leaderstats:FindFirstChild("Evo. Stone")
if evoStone then
	print("Deducting " .. requiredEvoStone .. " Evo. Stone from " .. player.Name)
	evoStone.Value = evoStone.Value - requiredEvoStone
end

print(player.Name .. " has been morphed successfully.")
return true

end

– Button click event
button.MouseButton1Click:Connect(function()
local player = players.LocalPlayer
if not player then
print(“No player found.”)
return
end

print("Button clicked by player: " .. player.Name)
morphPlayer(player)

end)

Screenshot 2024-11-25 144329
Screenshot 2024-11-25 144400