I’m using a script that is a state-like system where a part gets destroyed and a new gets cloned, it works but it’s very messy and it’s tedious to detect if it upgraded (like went from crude to unpolished) or degraded (perfect to crude), any ideas? I was thinking of using tables…
Is there also a way to make it so the event ONLY fires when the state gets changed?
-- THIS IS A .CHANGED CONNECTION FOR INTVALUE WITH VALUE BEING PASSED AS THE CHANGE INTVALUE.
if Value < 80 and Value > 60 and Moai.Moai.StateType.Value == "Perfect" or Moai.Moai.StateType.Value == "Crude" then -- unpolished state
Moai.Moai.DontAlert.Value = true
if Moai.Moai.StateType.Value == "Crude" then
Moai.Moai.StateType.Value = "Unpolished"
AlertEvent:FireClient(Players:FindFirstChild(Moai.Moai:FindFirstChild("Owner").Value), "YOUR MOAI HAS BEEN UPGRADED!") -- in this case it gets upgraded
else
Moai.Moai.StateType.Value = "Unpolished"
AlertEvent:FireClient(Players:FindFirstChild(Moai.Moai:FindFirstChild("Owner").Value), "YOUR MOAI HAS BEEN DEGRADED!") -- but in here it went from perfected to unpolished.
end
if Moai:FindFirstChild("Meshes/Clean") then
Moai["Meshes/Clean"]:Destroy()
else
Moai.Crude:Destroy()
end
local UnpolishedMoai: Part? = UnpolishedMesh:Clone()
UnpolishedMoai.CFrame = Moai.PrimaryPart.CFrame
UnpolishedMoai.Parent = Moai
elseif Value > 85 and Moai.Moai.StateType.Value ~= "Perfect" and Moai.Moai.DontAlert.Value == true then -- perfect state
Moai.Moai.DontAlert.Value = false
Moai.Moai.StateType.Value = "Perfect"
AlertEvent:FireClient(Players:FindFirstChild(Moai.Moai:FindFirstChild("Owner").Value), "YOUR MOAI HAS BEEN UPGRADED!")
Moai["Meshes/Unpolished"]:Destroy()
local PerfectMoai: Part? = PerfectMesh:Clone()
PerfectMoai.CFrame = Moai.PrimaryPart.CFrame
PerfectMoai.Parent = Moai
elseif Value < 60 and Value > 40 and Moai.Moai.StateType.Value ~= "Unpolished" or Moai.Moai.StateType.Value ~= "Stage 3" and Moai.Moai.StateType.Value ~= "Perfect" then
Moai.Moai.DontAlert.Value = true
if Moai.Moai.StateType.Value == "Unpolished" then
Moai.Moai.StateType.Value = "Crude"
AlertEvent:FireClient(Players:FindFirstChild(Moai.Moai:FindFirstChild("Owner").Value), "YOUR MOAI HAS BEEN DEGRADED!")
else
Moai.Moai.StateType.Value = "Crude"
AlertEvent:FireClient(Players:FindFirstChild(Moai.Moai:FindFirstChild("Owner").Value), "YOUR MOAI HAS BEEN UPGRADED!")
end
if Moai:FindFirstChild("Meshes/Unpolished") then
Moai:FindFirstChild("Meshes/Unpolished"):Destroy()
else
print(". . . ")
end
local PerfectMoai: Model? = Core.MoaiMeshes.Crude:Clone()
PerfectMoai:SetPrimaryPartCFrame(Moai.PrimaryPart.CFrame)
PerfectMoai.Parent = Moai
end