Attempt to index nil with 'Name'

Hello I made a bomb script and I get this error:

attempt to index nil with 'Name’

local Players = game:GetService("Players")
local plr

Players.PlayerAdded:Connect(function(player)
	plr = player
	repeat
	    wait(0.1)
    until workspace:FindFirstChild(player.Name.."Bomb").Fire.Value == true and script.Parent.Parent  ~= "ObjectFolder" -- error line
end)






local PartC = 0
local explosion = Instance.new("Explosion")
local PartCs = script.Parent.Parent.Parent.PartM
local PartCss = script.Parent.Parent.Parent.PartD






explosion.Hit:Connect(function(part, distance)
	if part.Name ~= "ExplosionPart" then
	  part.Anchored = false
	  if distance >= 25 then
		PartC += 1
		PartCss.Value += 1
		print(PartCs)
		print(part.Name.." was hit "..distance.." studs away from the explosion.")
	   else
		PartC += 1
		PartCs.Value += 1
		print(PartC)
		print(part.Name.." was hit "..distance.." studs away from the explosion.")	
	 end
   end
end)
explosion.Parent = workspace:FindFirstChild(plr.Name.."Bomb")
explosion.BlastRadius = 5
explosion.BlastPressure = 50000
explosion.Position = script.Parent.Position



local children = script.Parent.Parent:GetChildren()
for i = 1, #children do
	local child = children[i]
	child.CanCollide = false
	child.Transparency = 100
end

please help thanks :smiley:

explosion.Parent = workspace:FindFirstChild(plr.Name.."Bomb")

plr is equal to nil when this is run because plr only has a value after PlayerAdded is run

2 Likes

The wrong line I need to fix the error on this line

 until workspace:FindFirstChild(player.Name.."Bomb").Fire.Value == true and script.Parent.Parent  ~= "ObjectFolder" -- error line

Did you try changing player to plr? Or tostring(player)

yes, I tried but gave the same error.

Is this a local script or a server sided script?

server-side script. Probably I need to use remote functions. :frowning:

I tired this in studio and it worked.

local players = game:GetService("Players")
local plr = nil
players.PlayerAdded:Connect(function(player)
	plr = player
	print(tostring(plr))
end)

Try this:

local players = game:GetService("Players")
local plr = nil
Players.PlayerAdded:Connect(function(player)
	plr = player
	repeat
	    wait(0.1)
    until workspace:FindFirstChild(tostring(plr).."Bomb").Fire.Value == true and script.Parent.Parent  ~= "ObjectFolder" -- error line
end)
1 Like

If this doesn’t work you need to keep in mind

(tostring(plr).."Bomb")

Your seeing if the player in workspace is called something like:
ar_qxBomb
So if your code isn’t designed to do that reply.

1 Like

I saw your reply new, worked thanks for help

1 Like