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

attempt to index local 'char' (a nil value) why is this happening?

Asked by 4 years ago
local player = game.Players.LocalPlayer
local plot

local function MoveChar(char)
    wait(0.1)

    char:SetPrimaryPartCFrame(CFrame.new(plot.Plot.Spawn.CFrame.X,plot.Plot.Spawn.CFrame.Y + 5, plot.Plot.Spawn.CFrame.Z))
end

player.CharacterAdded:Connect(function(char)
    for i,v in pairs(workspace.Plots:GetChildren()) do
        if v then
            if v.Plot.Owner.Value == player then
                plot = v

                MoveChar()
                break
            end
        end
    end

end)

2 answers

Log in to vote
1
Answered by 4 years ago

The reason your code is not working as you are not sending over the "Char" as an argument when running your custom funtion. Thats an easy fix. Use this:

local player = game.Players.LocalPlayer
local plot

local function MoveChar(char)
    wait(0.1)

    char:SetPrimaryPartCFrame(CFrame.new(plot.Plot.Spawn.CFrame.X,plot.Plot.Spawn.CFrame.Y + 5, plot.Plot.Spawn.CFrame.Z))
end

player.CharacterAdded:Connect(function(char)
    for i,v in pairs(workspace.Plots:GetChildren()) do
        if v then
            if v.Plot.Owner.Value == player then
                plot = v

                MoveChar(char)
                break
            end
        end
    end

end)


0
i did not notice it tnx manzano30 5 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

dosent player.CharacterAdded only fire on the server? if not my bad

Answer this question