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

what to do if this is being shown in output? attempt to index nil with 'LoadCharacter'

Asked by 4 years ago
Edited 4 years ago

i have a made a script based on round system there is a problem shown in output it is not being showed in script Analysis. my script ends without being finished. please help me.

I am working on a Round System. i don't know much in scripting just running using Youtube. if there is a expert Person Who Know Scripting then can contact me let me know your user if you know scripting.

Script:

local s =script.Stat
local vals = game.ReplicatedStorage.vals
t = 0
while true do
    t = 15
    repeat
        t = t-1
        s.Value = "Intermission.. "..t
        wait(1)
    until t == 0
    s.Value = "Game Starting"
    wait(2)
    local mapselect = game.ReplicatedStorage.Games:GetChildren()
    local choose = math.random(1,#mapselect)
    curnum = 0
    for i =1,#mapselect do
        curnum = curnum +1
        if curnum == choose then
            mapselect[i]:Clone().Parent = workspace
            curnum = mapselect[i].Name
            s.Value = "We'll Be Playing "..mapselect[i].name
        end
    end
    wait(3)
    local plrs = game.Players:GetChildren()
    for i =1,#plrs do
        local num = math.random(1,32)
        plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
        plrs[i].Character.Parent = workspace.Ingame
    end
    t=100
    repeat
        t = t-1
        s.Value = t.." Seconds Left"
        wait(1)
    until t ==0 or vals.Winner.Value ~= ""
    if vals.Winner.Value ~= "" then
        s.Value = vals.Winner.Value.. "Has Won!"
        vals.Winner.Value = ""
    else
        s.Value = "No One Has Won!"
    end
    wait(3)
    local ingame = workspace.Ingame:GetChildren()
    for i =1,#ingame do
        local plr = game.Players:GetPlayerFromCharacter(ingame[i])
        plr:LoadCharacter()
        workspace[curnum]:Destroy() 
    end
end     

the proble according to output is in line 47

0
Are there any non-character models in "ingame" model? Problem is that it only gets player from character, so if it did not find the character then it is not in the model or there is some model that is not a character. imKirda 4491 — 4y
0
If you're planning to do a round system, use while wait() do and then use a for loop. Dovydas1118 1495 — 4y
0
no there are not any non-character models in" Ingame"  and Ingame is a Floder in Workspace KingUmerThe1 -3 — 4y

2 answers

Log in to vote
0
Answered by
Syclya 224 Moderation Voter
4 years ago

Simply check if the player exists, and their character:

if plr and plr.Character then
   -- load character here
end
Ad
Log in to vote
0
Answered by 4 years ago
for i =1,#ingame do
if game.Players:findFirstChild(ingame[i].Name) then
...
end

Answer this question