ClickDetector to ProximityPrompt

So i wanted to change clickdetector to proximityprompt but i have no idea how to use it

This is the script

for _,v in pairs(crateSystem:GetDescendants()) do
if v and v:IsA(‘ClickDetector’) and v.Name == ‘Crate_Detector’ then
v.MouseClick:connect(function(player)

Also im struggling with changing
v.MouseClick:connect
To proximityprompt

1 Like

Click the + Icon and click on Proximity prompt.
Add a script in the part and type the following

Click Detector | Proximity Prompt


Proximity Prompt

local part = script.Parent
local prompt = part.ProximityPrompt

prompt.Triggered:Connect(function(player)
 -- Code here
end)

Click Detector

local part = script.Parent
local click = part.ClickDetector

click.MouseClick:Connect(function(player)
 -- Code here
end)

Replacing Click Detector To Proximity Prompt

for _,v in pairs(crateSystem:GetDescendants()) do
     if v and v:IsA(‘ClickDetector’) then
       local prompt = Instance.new("ProximityPrompt")
       prompt.Parent = v.Parent

       task.spawn(function()
             prompt.Triggered:Connect(function(player)
                   -- Do stuff
            end)
       end)
       v:Destroy()
    end
end
1 Like

The script is located in serverscriptservice
you can see the whole model here if it helps you

Why would you need to use task.spawn for connections? It already creates a new thread when a connection is created

1 Like

Well, not gonna take any chances.
Sometimes when I use a roblox connection in for i,v loop then it doesn’t work.
So I’ve used task.spawn to prevent that.

Can you provide an example of this lol

it does look nicer but it’s pointless tbh