Event not binding to function inside a pairs loop

Yeah the second method didn’t work for me either, I also want to clarify my function was the exact same.

2 Likes

Just to be 100% sure, it’s the bottom iteration that isn’t working?

Currently the code you have for it is less efficient, using an extra function.

Try:

--if you don't want to use pairs() or ipairs()
for i, v in next, Updates:GetChildren(), nil do
    local prompt = v:FindFirstChildOfClass("ProximityPrompt")
    if not prompt then continue end
    prompt.Triggered:Connect(function(player)
        print("@"..player.Name.." triggered the prompt.")
    end)
end
1 Like

I didn’t get anything in the output.

1 Like

Check:

  • Updates:GetChildren() actually returns an array
  • They aren’t all just being skipped with continue

I’ve tested that method of iteration and it works, try others too. Debug with print statements.

You could just use GetDescendants() and check if it’s a prompt or not when iterating.

1 Like

Which container is ClickTools located in? Is it ServerStorage? If it is located in ServerStorage, is GunHandler's RunContext set to Server? By default, Scripts only run when they’re a descendant of workspace or ServerScriptService. Once you confirmed that, what @12345koip gave you here:

should work fine.

2 Likes

ClickTools is in the workspace, I also tried the high order function but it didn’t work, what I have displayed right now is me trying something new.

1 Like

They exist and you can print them out and the proximity prompts, all the instances, but it will never print a statement in the event.

1 Like

I’m not sure but check the properties of the prompt. Might be something wrong with those, if the code is running.

1 Like

Strange. Do you modify Suppression in any other script in the DataModel?

1 Like

Well RequiresLineOfSight is enabled.

1 Like

I haven’t modified the instance anywhere else.

1 Like

Do you have any lines of code in the module that might cause it to yield? If the module yields, the script requiring it yields too.

1 Like

I’m using a normal server script btw and nothing is yielding my code.

No, I mean in the module that you required. Yielding in there causes yielding in this script if it is calling a yielding thread.

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tools = ServerStorage.Tools
local Remotes = ReplicatedStorage.Remotes

local function FindWeaponInCharacter(player)
	local character = player.Character
	for i,v in Tools:GetChildren() do
		local tool = character:FindFirstChild(v.Name)
		if tool then
			return tool
		end
	end
end

local Distributer = {}

function Distributer:Init(player,instance)
	local backpack = player.Backpack
	local name = instance.Name
	local gun = Tools:FindFirstChild(name):Clone()
	gun.Parent = backpack
end

function Distributer:Upgrade(player,instance)
	if instance.Name == "Suppression" then
		self:Suppression(player)
		return
	elseif instance.Name == "FlashHider" then
		return
	
	end
end

function Distributer:Suppression(player)
	local tool = FindWeaponInCharacter(player)
	if tool then
		Remotes.ToClient:FireClient(player,"Suppression",tool)
	end
end

return Distributer

This is all my module has.

I’d also like to mention this script worked for me before its just not working for me now.

AI assistant said its a client-side event -

So does the prompt actually show up when you go close to it?

Nevermind, its not a client-side event. AI assistant lied to me and it didn’t work. What do you mean by close the proximity prompt?

I meant close, not close. As in you are near the prompt.

If the prompts exist, and the script knows they exist, it’s likely a problem with the prompts themselves.

The prompt exists, I unenabled RequiresLineOfSight and the prompt is enabled.