I am making a script so that you teleport to the associated checkpoint when you spawn in. I have a script under the player. And a folder filled with the checkpoints that have numbers as names. Checkpoints will randomly not work and then work. What should I do?
local replicatedstorage = game:GetService('ReplicatedStorage')
local teleport = replicatedstorage.Remotes.TeleportRemote
local players = game:GetService('Players')
local player = players.LocalPlayer
local leaderstats = player:WaitForChild('leaderstats')
local checkpointvalue = leaderstats:WaitForChild('Checkpoint')
local function TpToCheckpoint(char)
if checkpointvalue.Value ~= 1 then
local checkpoint = workspace.Stages:WaitForChild(checkpointvalue.Value)
teleport:FireServer(char:WaitForChild('HumanoidRootPart'), checkpoint:WaitForChild('Union').Position + Vector3.new(0,4,0),checkpoint.Configuration.Orientation.Value)
end
end
TpToCheckpoint(player.Character or player.CharacterAdded:Wait())
player.CharacterAdded:Connect(TpToCheckpoint)
First of all, you should tell us which of the following lines/paths is causing the yield:
player.leaderstats
leaderstats.Checkpoint
workspace.Stages[checkpointvalue.Value]
char.HumanoidRootPart
checkpoint.Union
At least give us the yield message so we can figure it out.
Also since this is related to the character, not the player, you can change the script location to StarterCharacterScripts to simplify the script:
--Make it a script instead of a local script
local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local checkpoint = player:WaitForChild("leaderstats"):WaitForChild("Checkpoint")
if checkpoint.Value == 1 then return end
local spawnPart = workspace.Stages:WaitForChild(checkpoint.Value)
local root = character:WaitForChild("HumanoidRootPart")
local pos = spawnPart:WaitForChild("Union").Position+Vector3.new(0,4,0)
local rot = spawnPart.Configuration.Orientation.Value
--Assuming Orientation to be a Vector3
local r = math.rad
root.CFrame = CFrame.new(pos)*CFrame.Angles(r(rot.X), r(rot.Y), r(rot.Z))
As long the spawnPart isn’t moving and doesn’t change sizes and such between stages, you can just offset the result to make it work(as you already do for height by adding 4).
I actually had this problem a lot before when making my game, What i did to fix it was make the parts higher up, because in my case, they would get deleted because they were too far from spawn, therefore making them deleted in the void. Sorry if this does not solve your problem, but its worth a try!
Could you provide some more details about the union part?
What size is the union? (like big, or small)
What would you have to move?
If the union doesn’t have to been seen or collided with, Then it shouldn’t exactly matter where its positioned at.
The union part is just an almost flat checkpoint. And its not very big. I have to move the player to it when spawning in. And the union does need to be seen when close enough and collided with.
Is there anything wrong with having it at 0,0,0 in studio? and then when the character respawns, move it there, that way, i dont think it should be deleted since it doesnt spawn in the void.
I think im failing to understand. do I move the character there? The problem isnt its spawning in the void. Its just out of render distance. And this is an obby
Alright, Then move the union closer to where ever players spawn, So it wont be deleted. Also, I meant move the character to the union, Not 0,0,0. Sorry for not specifying.