Hi,
I am trying to make a teleport block that only works when game.Workspace.BaseMap exists and do nothing when it doesn’t (between rounds).
Here is my current code in a script inside the teleport block:
function teleportPlayer(hit)
local spawnblock = {game.Workspace.BaseMap.Spawn1,game.Workspace.BaseMap.Spawn2,game.Workspace.BaseMap.Spawn3,game.Workspace.BaseMap.Spawn4,game.Workspace.BaseMap.Spawn5,game.Workspace.BaseMap.Spawn6,game.Workspace.BaseMap.Spawn7}
local target = CFrame.new(spawnblock[math.random(1,#spawnblock)].Position)
if hit.Parent:findFirstChild("Humanoid") ~= nil then
hit.Parent.Torso.CFrame = target
game.Workspace.Sounds.Teleport:Play()
end
end
script.Parent.Touched:Connect(teleportPlayer)
If have tried:
function teleportPlayer(hit)
local spawnblock = {game.Workspace.BaseMap.Spawn1,game.Workspace.BaseMap.Spawn2,game.Workspace.BaseMap.Spawn3,game.Workspace.BaseMap.Spawn4,game.Workspace.BaseMap.Spawn5,game.Workspace.BaseMap.Spawn6,game.Workspace.BaseMap.Spawn7}
local target = CFrame.new(spawnblock[math.random(1,#spawnblock)].Position)
if hit.Parent:findFirstChild("Humanoid") ~= nil and game.Workspace:findFirstChild("BaseMap") ~= nil then
hit.Parent.Torso.CFrame = target
game.Workspace.Sounds.Teleport:Play()
end
end
script.Parent.Touched:Connect(teleportPlayer)
and
function teleportPlayer(hit)
local spawnblock = {game.Workspace.BaseMap.Spawn1,game.Workspace.BaseMap.Spawn2,game.Workspace.BaseMap.Spawn3,game.Workspace.BaseMap.Spawn4,game.Workspace.BaseMap.Spawn5,game.Workspace.BaseMap.Spawn6,game.Workspace.BaseMap.Spawn7}
local target = CFrame.new(spawnblock[math.random(1,#spawnblock)].Position)
if hit.Parent:findFirstChild("Humanoid") ~= nil then
hit.Parent.Torso.CFrame = target
game.Workspace.Sounds.Teleport:Play()
end
end
if game.Workspace.BaseMap ~= nil then
script.Parent.Touched:Connect(teleportPlayer)
end
The first two work fine, but throw errors constantly between rounds saying the basemap doesn’t exist.
The third one doesn’t work at all.
I also tried putting the statement in the 2nd line. I tried it with WaitForChild and I tried doing if the basemap == nil then return else teleport, but nothing is preventing the error.
Can someone help me understand what I am doing wrong and why?
Thanks.