So, I am testing out proximity prompts and i was wondering if there is a way I can put all my coins with proximity prompts in them, into a folder and if a player picks up one of the coins with the proximity prompt then it finds their name and does the function.
I know how to use proximity prompts with just a script in side each coin… but I wanted to see if I could do it with one whole script.
local folder = workspace:WaitForChild("Folder")
for _, prompt in ipairs(folder:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function(player)
print(player.Name.." picked up a coin!")
--do stuff
end)
end
end
This is possible though. Will need to be a server script.
Was thinking about that, and I am going to be cloning parts into the group once one disappears and ther e is going to be a cap on how many can spawn in at once. But, I thought if I had like 40 parts and 1 script in side each part wouldnt that be excessive?
It is best to use as few scripts as possible, yes, the above will allow you to have 40+ prompts (or however many you decide) all tied to the same script.
local folder = workspace:WaitForChild("Folder")
for _, prompt in ipairs(folder:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function(player)
local part = prompt.Parent
print(player.Name.." picked up a coin!")
--do stuff
end)
end
end