Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is my script not creating any SpawnLocations?

Asked by 6 years ago
Edited 6 years ago

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.

01spawnlocation = Instance.new("SpawnLocation",workspace)
02 
03 
04function createSpawnA1()
05    spawnlocation.Transparency = 1
06    spawnlocation.CanCollide = false
07    spawnlocation.Position = Vector3.new(462,0.5,48)
08end
09 
10function createSpawnA2()
11    spawnlocation.Transparency = 1
12    spawnlocation.CanCollide = false
13    spawnlocation.Position = Vector3.new(462,0.5,28)
14end
15 
View all 58 lines...

2 answers

Log in to vote
1
Answered by 6 years ago

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

01local function createSpawn(position)
02    local spawnLoc = Instance.new("SpawnLocation") -- the parent argument is deprecated and is known to slow down performance, do not use it
03 
04    spawnLoc.Transparency = 1
05    spawnLoc:FindFirstChildOfClass("Decal").Transparency = 1
06    spawnLoc.CanCollide = false
07    spawnLoc.Position = position
08    spawnLoc.Parent = game.Workspace
09end
10 
11createSpawn(Vector3.new(462, .5, 48))
12-- you'd add the new XYZ coordinates on each call in a Vector3.new
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 ReynaldoVictarion 70 — 6y
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. ScrewDeath 153 — 6y
0
The spawnlocation DID spawn. It's only transparent. User#19524 175 — 6y
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. ReynaldoVictarion 70 — 6y
View all comments (6 more)
0
Got it, found a solution. Check out below the code I wrote, after the line ReynaldoVictarion 70 — 6y
1
Parent the spawn location as the LAST property if you care about performance User#19524 175 — 6y
0
Got it, thanks ReynaldoVictarion 70 — 6y
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? ReynaldoVictarion 70 — 6y
0
Something is destroying it then. The parent should always be the last property to assign. User#19524 175 — 6y
0
You're right, I'm doing something wrong, it's actually not what I said. I'll find out ReynaldoVictarion 70 — 6y
Ad
Log in to vote
3
Answered by 6 years ago

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:

1function createSpawnA1()
2    local spawnlocation = Instance.new("SpawnLocation")
3    spawnlocation.Transparency = 1
4    spawnlocation.CanCollide = false
5    spawnlocation.Position = Vector3.new(462,0.5,48)
6    spawnlocation.Parent = workspace -- doing this so someone don't backsass me
7end
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 ReynaldoVictarion 70 — 6y
0
Actually it disappears for about 2 seconds also. ReynaldoVictarion 70 — 6y
0
Use incapaz's answer as his is more thicc and reusable. ScrewDeath 153 — 6y
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 ReynaldoVictarion 70 — 6y

Answer this question