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

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

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

3 comments

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.

0

If you're planning to do a round system, use while wait() do and then use a for loop.

0

no there are not any non-character models in" Ingame"  and Ingame is a Floder in Workspace

2 answers

Simply check if the player exists, and their character:

if plr and plr.Character then
   -- load character here
end
for i =1,#ingame do
if game.Players:findFirstChild(ingame[i].Name) then
...
end

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