I've used this script in many cases, but lately, roblox keeps spawning people randomly in the sky, at random places, and not at my "plot" model with "BaseSpawnPoint" part in it. This is from my Tycoon.
So my issue, is the teleport part, where it teleports people to random places in workspace. Not to the specific tycoon part, that is bought as a spawn point.
I know that this will fail using R15, because it doesn't detect the torso (my game does not support R15 yet)
wait(3) --let the globals script load up
function onPlayerRespawn(property, player)
--check if player owns a base
local isOwner = false
local plot = nil
for i,v in pairs (shared.Bases) do
if workspace[v].Owner.Value == player.Name then
isOwner = true
plot = workspace[v]
break
end
end
if isOwner == false then return end
--check if player owns the teleport upgrade
if not plot:findFirstChild("BaseSpawnPoint") then return end
--calculate vector to the base spawn point pad
local vector = plot.BaseSpawnPoint.Position - player.Character.Torso.Position
--move player
for i,v in pairs (player.Character:GetChildren()) do
if v.className == "Part" then
v.CFrame = v.CFrame + vector
end
end
--play teleport sound
plot.BaseSpawnPoint.Sound:Play()
--sparklify player
for i,v in pairs (player.Character:GetChildren()) do
if v.className == "Part" then
local sparkles = Instance.new("Sparkles")
sparkles.Parent = v
game:GetService( "Debris" ):AddItem( sparkles, 0.5 )
end
end
end
function onPlayerEntered(newPlayer)
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
end
game.Players.ChildAdded:connect(onPlayerEntered)

2 comments
Before I check this to hard, is there an output?
It doesn't print anything, but it does execute, but at random places in workspace.