For the past months I been trying to fix a bug, where in my obby I play with certain players and each time I die it spawns me at the lobby then it takes like 5-10 seconds to respawn back to the checkpoint I am really Here is a small video of what I mean https://youtu.be/iLGI_TOoM6I Anybody who can fix the checkpoints it prevents me to have growth of players in this obby because of this bug please help me... I been trying fix it for months legit here is the script of the checkpoints they all have the same script;
local spawn = script.Parent spawn.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData") if not checkpointData then checkpointData = Instance.new("Model", game.ServerStorage) checkpointData.Name = "CheckpointData" end local checkpoint = checkpointData:FindFirstChild(tostring(player.userId)) if not checkpoint then checkpoint = Instance.new("ObjectValue", checkpointData) checkpoint.Name = tostring(player.userId) player.CharacterAdded:connect(function(character) wait() character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0) end) end checkpoint.Value = spawn end end)
GENERAL PRACTICE
Use the :GetService()
method to check for the "ServerStorage" and "Players" rather than immediately calling them.
You don't require the tostring()
on the UserId since the numbers can be directly taken by the script.
Considering how this code is written, it's probably better to separate the .Touched
and .CharacterAdded
events since you will have the character added before touching a part.
ISSUES
connect
is deprecated in favor of Connect
The actual Property name for a player's id is UserId
, not "userId"
Use the :SetPrimaryPartCFrame()
of models (the character is a model) to move the player since just moving their rootpart may sometimes cause the player's body to remain where it is and only move the one part.
spawn
is a function, so consider changing the name of this variable (my example switches it to "sp")
REVISED SERVER SCRIPT
game:GetService("Players").PlayerAdded:Connect(function(player) local objval = Instance.new("ObjectValue") objval.Name = "CheckpointData" objval.Value = nil objval.Parent = player player.CharacterAdded:Connect(function(character) repeat wait() until character:FindFirstChild("HumanoidRootPart") ~= nil if objval.Value ~= nil then character:SetPrimaryPartCFrame(objval.Value.CFrame + Vector3.new(0, 4, 0)) end end) end) for w, sp in pairs(workspace:WaitForChild("Checkpoints"):GetChildren()) do sp.Touched:Connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) local checkpointData = player:WaitForChild("CheckpointData") if checkpointData.Value ~= sp then checkpointData.Value = sp end end end) end