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

attempt to index nil with 'CFrame' ?

Asked by 4 years ago

Hello, my script has been working fine for a while now. But I get the error:

Workspace.Essential Scripts.Checkpoint Script:9: attempt to index nil with 'CFrame'

My script:

function oa(object)
local player = game.Players:GetPlayerFromCharacter(object)
if player ~= nil then
local ls = player.leaderstats
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
print("gah")
object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
wait()
object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
end end

function oe(object)
if object.className == "Player" then
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 1
ack2.Parent = ack
ack.Parent = object
end end

game.Players.ChildAdded:connect(oe)
game.Workspace.ChildAdded:connect(oa)
0
Thats because you cant add a cframe and a vector3. JesseSong 3916 — 4y
0
that would mean `s1` is nil... try adding a print statement to make sure its not `nil` User#23252 26 — 4y
0
This program is very deprecated Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Stage = Instance.new("IntValue")
    Stage.Name = "Stage"
    Stage.Value = 1
    Stage.Parent = Leaderstats
    Player.CharacterAdded:Connect(function(Characer)
        local Leaderstats = Player:FindFirstChild("leaderstats")
        if (Leaderstats and Leaderstats.Stage) then
            local Stage = workspace:FindFirstChild(tostring(Stage.Value))
            if (Stage) then
                Character:MoveTo(Stage.Position + Vector3.new(0,3,0)
            end
        end
    end)
end)
Ad

Answer this question