This morph script is a part that, when touched will morph you, however after I applied some updates to fix it, it stopped working in normal servers. This script usually works frequently in VIP servers and almost always in Studio.
The way the button functions as seen below is that it detects a human, if the human does not meet the prerequisites it will simply start over (by destroying itself and creating a new button from ServerStorage. I didn't know how to do this without destroying it otherwise the first person to use the button will have their money taken several times instead of other people using the button at the moment.) The other morphs that have a price of 0 always work. (If I change this price from 800 to 0 it will most definitely work.)
On the Output log, it reports trying to index a "nil" on "Destroy()" on line [67], where the restart function is. I am pretty sure destroying the button to fix nil values is not the way to go, however I found no other alternative.
--//Variables\\--
local Players = game:GetService("Players")
local price = 800
local morphs = game.ServerStorage.Morphs:FindFirstChild('ALN')
local body = morphs:FindFirstChild('Player_ALN')
--//ToolConfigurations\\--
local allow_duplicates = false
local ServerStorage = game:GetService("ServerStorage")
local toolNames = {"Tail"}
local toolsParent = ServerStorage.Tools
--//MainFunction\\--
function onTouched(hit)
--//HumanValues\\--
local char = hit.Parent
local hum = char:FindFirstChild("Humanoid")
local morf = char:FindFirstChild("Morphed")
local player = game.Players:GetPlayerFromCharacter(char)
local p = game.Players:GetChildren()
if hum then
print("FoundHuman")
if morf then
print("FoundMorph")
if morf.Value == false then
print("NotMorphed")
--//Rich Boy Check\\--
for i = 1, #p do
local cash = p[i].leaderstats:FindFirstChild("Money")
if cash.Value > price or cash.Value == price then
cash.Value = cash.Value - price
char:FindFirstChild("Morphed").Value = true
script.Parent.brickColor = BrickColor.new("Really black")
--(This Is where the morph transformation goes)--
wait(3)
--//Destroy\\--
print("EverythingWentWell")
restart()
else
print("Error:NotEnoughMoney")
--//Destroy\\--
restart()
end
end
else
print("AlreadyMorphed")
--//Destroy\\--
restart()
end
else
print("Morph Not Found")
--//Destroy--
restart()
end
else
print("Human Not Found")
--//Destroy\\--
restart()
end
end
function restart()
wait(3)
script.Parent:Destroy()
local newbutton = morphs:FindFirstChild("Button_ALN"):clone()
newbutton.Parent = game.Workspace
end
script.Parent.Touched:connect(onTouched)
