I don’t know what it’s called but this is what I want:
I want to spawn a castle from your level.
I don’t know what to do if your level does not match any of these:
local function spawnCastle(player, value)
local castle = CastlesFolder:FindFirstChild(tostring(value))
if castle then
local newCastle = castle:Clone()
newCastle.Name = player.Name.." Castle"
newCastle.Parent = Castles
end
end
What I want to happen:
If you are in Level 10 and the next castle is Level 15, then it would return the previous castle.
local function spawnCastle(player, value)
-- Check if current level is at least 15
if value >= 15 then
local castle = CastlesFolder:FindFirstChild(tostring(value))
if castle then
local newCastle = castle:Clone()
newCastle.Name = player.Name.." Castle"
newCastle.Parent = Castles
end
else
-- If current level is less than 15, return previous castle
local castle = CastlesFolder:FindFirstChild(tostring(value - 5))
if castle then
local newCastle = castle:Clone()
newCastle.Name = player.Name.." Castle"
newCastle.Parent = Castles
end
end
end
local function spawnCastle(player, value) <---- value is the player level
local castle = CastlesFolder:FindFirstChild(tostring(value))
if castle then
local newCastle = castle:Clone()
newCastle.Name = player.Name.." Castle"
newCastle.Parent = Castles
end
end
local function spawnCastle(player, value)
-- Check if next level is at least 15
if value + 5 >= 15 then
local castle = CastlesFolder:FindFirstChild(tostring(value + 5))
if castle then
local newCastle = castle:Clone()
newCastle.Name = player.Name.." Castle"
newCastle.Parent = Castles
end
else
-- If next level is less than 15, return current castle
local castle = CastlesFolder:FindFirstChild(tostring(value))
if castle then
local newCastle = castle:Clone()
newCastle.Name = player.Name.." Castle"
newCastle.Parent = Castles
end
end
end
The code appears to be a Lua script that defines a function called “spawnCastle”. It takes two arguments, “player” and “value”, and checks if the next level is at least 15. If it is, it clones the castle model corresponding to the next level and renames it with the player’s name. Otherwise, it clones the castle model corresponding to the current level and renames it with the player’s name. It then sets the parent of the new castle model to the “Castles” object.