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 5 years ago
01local player = game.Players.LocalPlayer
02local plot
03 
04local function MoveChar(char)
05    wait(0.1)
06 
07    char:SetPrimaryPartCFrame(CFrame.new(plot.Plot.Spawn.CFrame.X,plot.Plot.Spawn.CFrame.Y + 5, plot.Plot.Spawn.CFrame.Z))
08end
09 
10player.CharacterAdded:Connect(function(char)
11    for i,v in pairs(workspace.Plots:GetChildren()) do
12        if v then
13            if v.Plot.Owner.Value == player then
14                plot = v
15 
View all 22 lines...

2 answers

Log in to vote
1
Answered by 5 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:

01local player = game.Players.LocalPlayer
02local plot
03 
04local function MoveChar(char)
05    wait(0.1)
06 
07    char:SetPrimaryPartCFrame(CFrame.new(plot.Plot.Spawn.CFrame.X,plot.Plot.Spawn.CFrame.Y + 5, plot.Plot.Spawn.CFrame.Z))
08end
09 
10player.CharacterAdded:Connect(function(char)
11    for i,v in pairs(workspace.Plots:GetChildren()) do
12        if v then
13            if v.Plot.Owner.Value == player then
14                plot = v
15 
View all 22 lines...
0
i did not notice it tnx manzano30 5 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question