Attempt to Index nil with 'Name' - Help would be appreciated

Hello Developers,

I have been trying to create a portal system for my game (I thought it was going to be simple) but because I’m very new to scripting I have an error that I don’t know how to fix. Here is the error:

Players.cookie0609life.PlayerGui.Frames.BuyPortal.Handler:17: attempt to index nil with ‘Name’

And here is the script:

wait()
local INFO = script.Parent.Info
local Title = script.Parent.Title.TextLabel
local Portal = game:WaitForChild("Workspace").MainMap.Portals:GetChildren()
local RS = game:WaitForChild("ReplicatedStorage")
local EVENt = RS.RemoteEvents.PurchaseWorld

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.RemoteEvents.PurchaseWorld

local price = Portal.price

remoteEvent.OnClientEvent:Connect(function(Portal, price)
		wait()

		script.Parent.Visible = true
		Title.Text = "Buy" .. Portal.Name
		script.Parent.Title.CopyTTExt.Text = "Buy" .. Portal.Name

		INFO.Text = "Would you like to buy " .. Portal.Name .. " For " .. price.Value
		
end)

local BuyBUTTON = script.Parent.BuyButton
local CancelBUTTON = script.Parent.CancelButton

if script.Parent.Visible == true then
	BuyBUTTON.MouseButton1Down:Connect(function(plr)
		if plr.leaderstats.Clicks.Value >= Portal.price.Value then
			wait()	
			plr.leaderstats.Clicks.Value = plr.leaderstats.Clicks.Value - Portal.price.Value
			script.Parent.Visible = false
			Portal.PortalHitBox.Script.Disable = false
			wait()
		else
			local ErrorText = Instance.new("TextLabel")
			ErrorText.Parent = script.Parent.Parent.Parent.Indicators.ErrorPopup
			ErrorText.Text = "Error: Not enough Coins"
			wait(3)
			ErrorText:Destroy()

		end
	end)

	CancelBUTTON.MouseButton1Down:Connect(function ()

		script.Parent.Visible = false
		local CancelText = Instance.new("TextLabel")
		CancelText.Parent = script.Parent.Parent.Parent.Indicators.ErrorPopup
		CancelText.Text = "Server: Cancelled Purchase"
		wait(3)
		CancelText:Destroy()

	end)
end

The script opens a GUI popup when a client event is fired.
The error happens on line 17. I’m very new to scripting so sorry if its terrible. But if anyone could help me, I would be very thankful.

How is the server sending Portal to the client? If the Portal Instance only exists on the server (ServerStorage, ServerScriptService) then it will appear nil on the client due to the fact that the client cannot see anything parented to those services.

Actually, you can with RemoteFunctions I think,
Anyways just make sure Portal exists somewhere in workspace, try printing Portal when remoteEvent is fired to the client

When I try that It prints nil, which is what zyro said

Can you give us the script that fires the remote event to the client?
Not much we can do without knowing what Portal is supposed to be.

So how could I make it exist in the client, or change it so it works on the server

Place the portal in ReplicatedStorage and that should fix your issue

Ok here it is:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		local RS = game:WaitForChild("ReplicatedStorage")
		local remoteEvent = RS.RemoteEvents.PurchaseWorld
		
		remoteEvent:fireClient(plr)

	end
end)
1 Like

portal is a part in the workspace. So when it is touched the Event is fired

1 Like

You aren’t passing any parameters into it.
It should be something like

remoteEvent:FireClient(plr, Portal, price) -- Also the 'F' in FireClient needs to be capitalized as well

Judging by what is firing the touched event I’m guessing the script is inside a portal?
If so then you can just pass in ‘script.Parent’.

1 Like

Ok, so put in the parameters, but instead of it printing the name of the portal it prints ‘price’

wait()

local INFO = script.Parent.Info
local Title = script.Parent.Title.TextLabel
local Portal = game:WaitForChild("Workspace").MainMap.Portals:GetChildren()
local RS = game:WaitForChild("ReplicatedStorage")
local EVENt = RS.RemoteEvents.PurchaseWorld
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.RemoteEvents.PurchaseWorld
local price = Portal.price

remoteEvent.OnClientEvent:Connect(function(plr, Portal, price)

wait()

print(Portal)

end)

Don’t include plr when detecting the signal from the client as you can already get the player from the client

remoteEvent.OnClientEvent:Connect(function(Portal, price)

Your client-side connection should look like this ^

2 Likes

Yes! Thankyou, it works. Very much appreciated :grin:

Thankyou So much for the help! :grin: