Is there a way I can make this code less cluttered? It’s for a tycoon and it checks which coloured tycoon they had because all the tycoons are different and then replaces the tycoons with the correct colour tycoon.
Edit: OtherBase is a placeholder
if player.Base.Value == "BlueBase" then
-- Create a new base
local newBase = storage.BlueBase:clone()
-- Move the clone into the world
newBase.Parent = workspace
-- Put the new base where the old base was
newBase:SetPrimaryPartCFrame(location)
elseif player.Base.Value == "OtherBase1" then
-- Create a new base
local newBase = storage.OtherBase1:clone()
-- Move the clone into the world
newBase.Parent = workspace
-- Put the new base where the old base was
newBase:SetPrimaryPartCFrame(location)
elseif player.Base.Value == "OtherBase2" then
-- Create a new base
local newBase = storage.OtherBase2:clone()
-- Move the clone into the world
newBase.Parent = workspace
-- Put the new base where the old base was
newBase:SetPrimaryPartCFrame(location)
elseif player.Base.Value == "OtherBase3" then
-- Create a new base
local newBase = storage.OtherBase3:clone()
-- Move the clone into the world
newBase.Parent = workspace
-- Put the new base where the old base was
newBase:SetPrimaryPartCFrame(location)
end
function Put()
local newBase = storage.Base:Clone()
newBase.Parent = workspace
newBase:SetPrimaryPartCFrame(location)
end
local BaseNames = {
"BlueBase", "OtherBase1", "OtherBase2", "OtherBase3"
}
if table.find(BaseNames, player.Base.Value) then
Put()
end
Name them all “base”…number and in the script you can loop through all the bases like:
for i, v in ipairs(storage.Bases:GetChildren()) do
if v.Name == "Base"..Base.Value then -- < int but you can do Base.Value if it's a string
local v:Clone = v:Clone()
clone:SetPrimaryPartCFrame(location)
end
end)
I found a better fix today, thanks for the help guys though!
-- Reset the base
if player.Base.Value then
-- Save the old base's location
local location = player.Base.Value:GetPrimaryPartCFrame()
-- Save the old base's name
local baseName = player.Base.Value.Name
-- Destroy the old base
player.Base.Value:Destroy()
-- Create a new base
local newBase = storage:FindFirstChild(baseName):Clone()
-- Move the clone into the world
newBase.Parent = workspace
-- Put the new base where the old base was
newBase:SetPrimaryPartCFrame(location)
end
end
game.Players.PlayerRemoving:Connect(savePlayerData)