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.

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

Log in to vote
1
Answered by 6 years ago

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
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:


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