Why can't it find the shop?

i want proximity prompts with a certain attribute to be visible to the client

Local Script:

Remotes.Claimed.OnClientEvent:Connect(function(shop)
	for _, v in workspace.Shops:GetDescendants() do
		if v:IsA("ProximityPrompt") and v:GetAttribute("ClientPrompt") == nil then
			v.Enabled = false
		end
	end
	
	if shop == nil then
		print("Could not find shop")
		return
	end
	
	for _, v in shop:GetDescendants() do
		if v:IsA("ProximityPrompt") then
			v.Enabled = true
		end
	end
end)

Server Side:

	local newTemp = ShopTemp:Clone()
	Remotes.Claimed:FireClient(player, newTemp)

If you use SetAttribute at all, it will have the attribute set to false, so checking if it’s nil won’t work.

for i, v in next, workspace.Shops:GetDescendants(), nil do
    if v:IsA("ProximityPrompt") and v:GetAttribute("ClientPrompt") == false then --no logic statement, that would check if it exists.
        --do stuff
    end
end

i’ve never seen “next” :thinking: what is it?

also i never use SetAttribute the attribute is already set

It is just an iteration function, to be fair you don’t even need to use them now you can just do loops like the following

for i, v in workspace.Shops:GetDescendants() do
    if v:IsA("ProximityPrompt") and v:GetAttribute("ClientPrompt") == false then --no logic statement, that would check if it exists.
        --do stuff
    end
end
Players.xiiitixxtxxtxxxxiiix.PlayerScripts.MainClient:18: attempt to index nil with 'GetDescendants'  -  Client - MainClient:18```

Try using this, maybe it hasn’t replicated yet

for i, v in workspace:WaitForChild("Shops"):GetDescendants() do
    if v:IsA("ProximityPrompt") and v:GetAttribute("ClientPrompt") == false then --no logic statement, that would check if it exists.
        --do stuff
    end
end

this is where it errors

	for _, v in shop:GetDescendants() do
		if v:IsA("ProximityPrompt") then
			v.Enabled = true
		end
	end

Can you show me your shop variable please

its the parameter “shop” in the local script

	Remotes.Claimed:FireClient(player, newTemp)

Have you tried printing it at all?

yes and it just says that shop is nil

Can I see all the code please? the sections related at least

Oh i see now actually, you must parent the instance before sending it over to the client, as it would not of replicated at all, parent it to the workspace or at least replicated storage

2 Likes

have you tried to parent the shop?

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