ProximityPrompt not Triggering?

  1. I currently have “ShirtObjects” constantly being cloned into the game and every “ShirtObject” contains a ProximityPrompt, and when triggered it prints(“KWSKKHFCEHWEKW”)

  2. For some reason the ProximityPrompt just isn’t working. I feel like this is so simple but my lack of knowledge is frustrating

(SERVER SCRIPT) For Triggering Prompt V

local Factory = script.Parent
local ShirtObject = Factory:FindFirstChild("ShirtObject")

for i, ShirtObject in Factory:GetChildren() do
	if ShirtObject.Name == "ShirtObject" then
		for i, Prompt in ShirtObject:GetChildren() do
			if Prompt.Name == "ProximityPrompt" then
				Prompt.Triggered:Connect(function()
					print("KHRBWEVHBWKJVBNWEREVBEUBRVHNER")
				end)
			end
		end
	end
end

(SERVER SCRIPT) For Spawning “ShirtObject” V

--Vars & Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShirtGenPart = script.Parent
local FactoryObjects = ReplicatedStorage.FactoryObjects
local ShirtObject = FactoryObjects:WaitForChild("ShirtObject")

if ShirtObject then
	while true do
		local ShirtClone = ShirtObject:Clone()
		ShirtClone.Parent = ShirtGenPart.Parent.Parent
		ShirtClone.CFrame = ShirtGenPart.CFrame
		task.wait(2)
	end
end

Maybe try without the for loop.

try this

	if ShirtObject.Name == "ShirtObject" then
		for i, Prompt in ShirtObject:GetChildren() do
			if Prompt.Name == "ProximityPrompt" then
				Prompt.Triggered:Connect(function()
					print("KHRBWEVHBWKJVBNWEREVBEUBRVHNER")
				end)
			end
		end
	end

Don’t know if it works, but worth a try.

Is this script refreshed each time a new item is added to the Factory folder?

local Factory = script.Parent
local ShirtObject = Factory:FindFirstChild("ShirtObject")

for i, ShirtObject in Factory:GetChildren() do
	if ShirtObject.Name == "ShirtObject" then
		for i, Prompt in ShirtObject:GetChildren() do
			if Prompt.Name == "ProximityPrompt" then
				Prompt.Triggered:Connect(function()
					print("KHRBWEVHBWKJVBNWEREVBEUBRVHNER")
				end)
			end
		end
	end
end

If not, the new ShirtObjects will not be found. You can use ChildAdded to refresh the script.

Also, you don’t need this line:

local ShirtObject = Factory:FindFirstChild("ShirtObject”)

You are defining ShirtObject with this line:

for i, ShirtObject in Factory:GetChildren() do

You need to register the trigger event for every shirt object that comes (optional: remove the event for every shirt object that goes. I’ll add that in here). We do this by listening for when a child is added and removed

local factory = script.Parent
local pcons = {}
factory.ChildAdded:Connect(function(child)
   if child.Name == “ShirtObject” then
      if pcons[child] then return end
      pcons[child] = child:FindFirstChild(“ProximityPrompt”).Triggered:Connect(function()
         print(“hdifj”)
      end)
   end
end)
factory.ChildRemoved:Connect(function(child)
   If child.Name == “ShirtObject” then
      if not pcons[child] then return end
      pcons[child]:Disconnect()
   end
end)
2 Likes

I made this script and it works!

local Factory = script.Parent
local ShirtTool = game:GetService("ReplicatedStorage").FactoryObjects.ShirtTool

Factory.ChildAdded:Connect(function(ShirtObject)
	if ShirtObject.Name == "ShirtObject" then
		local ProximityPrompt = ShirtObject:FindFirstChild("ProximityPrompt")
		if ProximityPrompt then
			ProximityPrompt.Triggered:Connect(function(User)
				if not User.Character:FindFirstChild("ShirtTool") then
					ShirtTool:Clone().Parent = User.Character
					ShirtObject:Destroy()
				end
			end)
		end
	end
end)

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