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

Checkpoints not working after spawned in from ReplicatedStorage?

Asked by 6 years ago
Edited 6 years ago

I used the default Roblox Obby template checkpoints in my game. For some reason they will NOT work as checkpoints after they are spawned in from ReplicatedStorage. It didn't work in playtest mode until I made the script search for humanoidrootpart instead of torso, and it works in studio. But it won't work in server mode. For anyone who wants to know, here is the script. Might I add it works for the first checkpoint cloned out of replicatedstorage

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)

Answer this question