This is originally intended for bug reports.
Sadly I can’t submit it to that forum yet.
A detailed description
When you use :Clone() on a model containing a ProximityPrompt the function that the ProximityPrompt should fire does not clone along.
How to replicate the bug
Start with an empty baseplate
Add a script and a part with a ProximityPrompt
In the image bove. the blue arrow points to the script and the red arrow to the ProximityPrompt that we want to clone
The code to insert into the script is:
script.Parent.promt.ProximityPrompt.Triggered:Connect(function()
print("It works")
end)
local new = script.Parent.promt:Clone()
new.Position=Vector3.new(0,10,0)
new.Parent=workspace
When walking to the original part and triggering the ProximityPrompt it will output “It works”
When walking to the cloned part and triggering the ProximityPrompt it does nothing.
script.Parent.promt:SetAttribute("PromptType1", true)
local function listenTrigger(Proximity:ProximityPrompt)
if Proximity:GetAttribute("PromptType1") then
Proximity.Triggered:Connect(function()
print("It works")
end)
end
end
listenTrigger(script.Parent.promt.ProximityPrompt)
game.Workspace.DescendantAdded:Connect(listenTrigger)
local new = script.Parent.promt:Clone()
new.Position=Vector3.new(0,10,0)
new.Parent=workspace
If you want that same function to run every time you trigger a ProximityPrompt (any proximity prompt), just remove this condition and listenPrompt to every ProimityPrompt.
New Script
local function listenTrigger(Proximity:ProximityPrompt)
Proximity.Triggered:Connect(function()
print("It works")
end)
end
for _, proximity:ProximityPrompt in pairs(game.Workspace:GetDescendants()) do
listenTrigger(proximity)
end
game.Workspace.DescendantAdded:Connect(listenTrigger)
local new = script.Parent.promt:Clone()
new.Position=Vector3.new(0,10,0)
new.Parent=workspace