I currently have “ShirtObjects” constantly being cloned into the game and every “ShirtObject” contains a ProximityPrompt, and when triggered it prints(“KWSKKHFCEHWEKW”)
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
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
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.
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)
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)