Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)


1 comment

0

i did not notice it tnx

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

This discussion is preserved as it was. New answers, comments, and votes are closed.