Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my script not creating any SpawnLocations?

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()




2 answers

✓ Accepted answer

###You wouldn't need a separate function for each spawn.

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

10 comments

0

It doesn't seem to work for me. I copied your code and pasted it into a new script and removed my script. No Spawn Location seems to show up

0

I suggest you put this script in a whole new place and check to see if it works. There's probably another script conflicting with this one in your current work environment.

0

The spawnlocation DID spawn. It's only transparent.

0

Tried the script in a fresh new place and it still doesn't show up for me anywhere. I even tried changing the transparency back to 0. I don't know what's happening.

0

Got it, found a solution. Check out below the code I wrote, after the line

1

Parent the spawn location as the LAST property if you care about performance

0

Got it, thanks

0

Hey, just a quick mention; when I parent the spawn as the last property, that seems to be the cause of the Spawn Location disappearing after about 2 seconds. I know this because when I parent the spawn as the first property, it works fine. Do you happen to know why this is?

0

Something is destroying it then. The parent should always be the last property to assign.

0

You're right, I'm doing something wrong, it's actually not what I said. I'll find out

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

4 comments

0

It doesn't seem to work for me. I copied your code and pasted it into a new script and removed my script. No Spawn Location seems to show up

0

Actually it disappears for about 2 seconds also.

0

Use incapaz's answer as his is more thicc and reusable.

0

I can't figure out why your code makes the Spawn Location disappear. I'm comparing it to the solution I got and they both look the same

This discussion is preserved as it was. New answers, comments, and votes are closed.