What I want: I want to create 6 separate Spawn Locations with different positions on my Baseplate. I want them to be invisible, and I want their CanCollide to be false.
What I get: As soon as I run my game, I take a look at the workspace. What I see is one Spawn Location that disappears after about 2 seconds.
I checked my spelling, keywords, punctuation. I checked the output, has no errors. I don't know what's going on. Please help.
spawnlocation = Instance.new("SpawnLocation",workspace) function createSpawnA1() spawnlocation.Transparency = 1 spawnlocation.CanCollide = false spawnlocation.Position = Vector3.new(462,0.5,48) end function createSpawnA2() spawnlocation.Transparency = 1 spawnlocation.CanCollide = false spawnlocation.Position = Vector3.new(462,0.5,28) end function createSpawnA3() spawnlocation.Transparency = 1 spawnlocation.CanCollide = false spawnlocation.Position = Vector3.new(462,0.5,8) end function createSpawnB1() spawnlocation.Transparency = 1 spawnlocation.CanCollide = false spawnlocation.Position = Vector3.new(-237,0.5,9) end function createSpawnB2() spawnlocation.Transparency = 1 spawnlocation.CanCollide = false spawnlocation.Position = Vector3.new(-237,0.5,29) end function createSpawnB3() spawnlocation.Transparency = 1 spawnlocation.CanCollide = false spawnlocation.Position = Vector3.new(-237,0.5,49) end createSpawnA1() createSpawnA2() createSpawnA3() createSpawnB1() createSpawnB2() createSpawnB3() ----------------------------------------------------------------------------- --This works function createSpawn() local spawnLocation = Instance.new("SpawnLocation") spawnLocation.CanCollide = false spawnLocation.Position = Vector3.new(-11, 0.5, -28) spawnLocation.Transparency = 1 spawnLocation.Parent = workspace end createSpawn()
local function createSpawn(position) local spawnLoc = Instance.new("SpawnLocation") -- the parent argument is deprecated and is known to slow down performance, do not use it spawnLoc.Transparency = 1 spawnLoc:FindFirstChildOfClass("Decal").Transparency = 1 spawnLoc.CanCollide = false spawnLoc.Position = position spawnLoc.Parent = game.Workspace end createSpawn(Vector3.new(462, .5, 48)) -- you'd add the new XYZ coordinates on each call in a Vector3.new
I'm not sure why it's disappearing after 2 seconds, however, this is because you are using the same SpawnLocation object in all the function calls.
To fix this, try instantiating the SpawnLocation within the function definition like so:
function createSpawnA1() local spawnlocation = Instance.new("SpawnLocation") spawnlocation.Transparency = 1 spawnlocation.CanCollide = false spawnlocation.Position = Vector3.new(462,0.5,48) spawnlocation.Parent = workspace -- doing this so someone don't backsass me end