Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help fixing my obby checkpoints if U can help please do?

Asked by 6 years ago

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;

01local spawn = script.Parent
02spawn.Touched:connect(function(hit)
03    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
04        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
05        local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
06        if not checkpointData then
07            checkpointData = Instance.new("Model", game.ServerStorage)
08            checkpointData.Name = "CheckpointData"
09        end
10 
11        local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
12        if not checkpoint then
13            checkpoint = Instance.new("ObjectValue", checkpointData)
14            checkpoint.Name = tostring(player.userId)
15 
View all 24 lines...

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

01game:GetService("Players").PlayerAdded:Connect(function(player)
02    local objval = Instance.new("ObjectValue")
03    objval.Name = "CheckpointData"
04    objval.Value = nil
05    objval.Parent = player
06 
07    player.CharacterAdded:Connect(function(character)
08        repeat wait() until character:FindFirstChild("HumanoidRootPart") ~= nil
09        if objval.Value ~= nil then
10            character:SetPrimaryPartCFrame(objval.Value.CFrame + Vector3.new(0, 4, 0))
11        end
12    end)
13end)
14 
15for w, sp in pairs(workspace:WaitForChild("Checkpoints"):GetChildren()) do
View all 25 lines...
0
Can you give me steps what to do how to use this REVISED script because I read what you typed and I understood why but for some reason I dont know how to put it correctly, however When I used this REVISED script I tried putting it on many ways of u said like server storage etc, can you give steps to what to do when im in the studio because every object of a checkpoint has the same script inside marioet77 13 — 6y
0
I think you have to put it in the ServerScriptService or in the Checkpoint blocks/parts robthepoop123 9 — 5y
Ad

Answer this question