I’m trying to make the character of the player to teleport back to a Spawn Location, but instead the character falls into the void and doesn’t teleport at all, why?
--LocalScript
local HRP = game.Players.LocalPlayer.Character.HumanoidRootPart
function respawnchr()
for i, v in next, workspace:GetDescendants() do
if v:IsA("SpawnLocation") then
local newpos = v.CFrame * CFrame.new(0,v.Size.Y/2+30,0)
HRP = CFrame.new(newpos)
return
end
end
HRP = CFrame.new(0,50,0)
end
game:GetService("RunService").RenderStepped:Connect(function()
if HRP.Position.Y<=workspace.FallenPartsDestroyHeight + 20 then
respawnchr()
end
end)
doing HRP = CFrame.new(newpos) just means you’re overriding the HRP variable to the cframe value, use HRP.CFrame = <cframe> instead
function respawnchr()
for i, v in next, workspace:GetDescendants() do
if v:IsA("SpawnLocation") then
local newpos = v.CFrame * CFrame.new(0,v.Size.Y/2+30,0)
HRP.CFrame = CFrame.new(newpos)
return
end
end
HRP.CFrame = CFrame.new(0,50,0)
end
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Run = game:GetService("RunService")
local function respawnchr()
for _, v in ipairs(workspace:GetDescendants()) do
if v:IsA("SpawnLocation") then
local newpos = v.CFrame * CFrame.new(0, v.Size.Y/2+30, 0)
HRP.CFrame = newpos
return
end
end
HRP.CFrame = CFrame.new(0,50,0)
end
Run.RenderStepped:Connect(function()
if HRP.Position.Y <= workspace.FallenPartsDestroyHeight + 20 then
respawnchr()
end
end)