Answered by
6 years ago Edited 6 years ago
The main problem with this is that you are using a loop to first remove anything named "handle" then afterwards are just cloning a handle into anything that is a "Part" by its Position. If you want the script to add the new Handle to a specific part, you will have to define the name of v in the function to do so (as v represents all objects in the workspace).
If you only wanted one handle to be cloned, you'd have to add a line designating that if there is a handle, then to either return end (much like a debounce) or just not perform the clone, such as:
01 | local click = script.Parent.ClickDetector |
04 | click.MouseClick:Connect( function (clicked) |
06 | local rand = math.random( 1 , 512 ) |
07 | for _, v in pairs (workspace.Mine:GetDescendants()) do |
08 | if v.Name = = "Handle" then |
10 | elseif v:IsA( "Part" ) and v.Name ~ = "Handle" then |
11 | local check = workspace:FindFirstChild( "Handle" ) |
12 | if Number = = rand and check = = nil then |
13 | local Clone = game.ServerStorage.Handle:Clone() |
14 | Clone.Parent = workspace |
15 | Clone.Position = v.Position |
Edits: Moved a redundant if-then you didnt need, added a check, used break to stop the for loop.