Attempt to index nil with wait for child?

Hey, so I was writing code for a leaderstats wall, then I encountered a error, I have tried fixing it with no luck. If anyone knows why, let me know.
Here is the code:
ServerScript (Inside Part):

script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
if not char then
return – Exit the function if hit.Parent is nil
end

local world = workspace.World1
local barrier = script.Parent.Parent:WaitForChild("Barrier")
local humanoid = char:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)

if humanoid and player and player.leaderstats then
	local minedValue = player.leaderstats:FindFirstChild("Mined")
	if minedValue and minedValue:IsA("NumberValue") and minedValue.Value >= script.Parent.Price.Value then
		if world and barrier then
			print("sent")
			game.ReplicatedStorage.RemoteEvents.touchedWall:FireClient(player, world.Name, barrier.Name)
		else
			print("World or barrier not found.")
		end
	else
		print("Insufficient mined value.")
	end
end

end)

Client Script Inside StartPlayerScripts:

game.ReplicatedStorage.RemoteEvents.touchedWall.OnClientEvent:Connect(function(player, world, wall )
local worldFound = workspace:FindFirstChild(world)
local WallFound = worldFound:WaitForChild(wall)

if worldFound then
	print("Founed")
	
end

end)

1 Like

Are you sure that this exist where you expect it to be:
local barrier = script.Parent.Parent:WaitForChild("Barrier")

Same for this:
local WallFound = worldFound:WaitForChild(wall)

Which line is the one with the error?

1 Like

Lined 4 Client Script and yes everything is correctly name.

1 Like

The issue is on the client script then? in this line?:
local WallFound = worldFound:WaitForChild(wall)

1 Like

yes it is, but i have fixed the issue so you don’t need to worry abt it.

2 Likes

if it is solved, please post the solution and mark the topic as solved with the solution

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.