I am making a funny little tool for my game which when you hold it and click, it will clone itself (the handle as that is what I want to clone) and put itself into the Workspace so it is visible to the players, and then destroy itself 10 seconds later. I was thinking of doing the :Destroy() thing and did, but it deleted the ACTUAL tool that the player has.
The problem is that it clones itself a bit too much, and lags the game. Here is a video (poorly recorded): robloxapp-20210830-1729456.wmv (4.2 MB)
Code:
local friend = script.Parent
local ball = friend.Handle
while true do
script.Parent.Activated:Connect(function()
local ballClone = ball:Clone()
ballClone.Name = "Friend's Friend"
ballClone.Parent = workspace
ballClone.CanCollide = true
ballClone.Position = ball.Position
wait(10)
end)
wait(1)
end
add a debounce so it doesnt spawn so much and try ballClone:Destroy()
local friend = script.Parent
local ball = friend.Handle
db = true
while true do
wait()
script.Parent.Activated:Connect(function()
if db == true then
db = false
local ballClone = ball:Clone()
ballClone.Name = "Friend's Friend"
ballClone.Parent = workspace
ballClone.CanCollide = true
ballClone.Position = ball.Position
wait(1)
db = true
wait(9)
ballClone:Destroy()
end
end)
end
I just modified my own script to have a debounce and a ballClone:Destroy() but it destroys the ballClone too fast.
Code:
local friend = script.Parent
local ball = friend.Handle
local db = false
while true do
if db == false then
db = true
script.Parent.Activated:Connect(function()
local ballClone = ball:Clone()
ballClone.Name = "Friend's Friend"
ballClone.Parent = workspace
ballClone.CanCollide = true
ballClone.Position = ball.Position
ballClone:Destroy()
wait(10)
end)
wait(1)
db = false
else
db = false
script.Parent.Activated:Connect(function()
local ballClone = ball:Clone()
ballClone.Name = "Friend's Friend"
ballClone.Parent = workspace
ballClone.CanCollide = true
ballClone.Position = ball.Position
wait(10)
ballClone:Destroy()
end)
wait(1)
db = true
end
end
it depends. If you want it just to check if someone activated it, then remove the loop, that will of course prevent spam. If you want the loop to stop, make sure to state an if statment that will break the loop with the command “break” once it respectes a condition
db = true
script.Parent.Activated:Connect(function()
if db == true then
db = false
local ballClone = ball:Clone()
ballClone.Name = "Friend's Friend"
ballClone.Parent = workspace
ballClone.CanCollide = true
ballClone.Position = ball.Position
wait(1)
db = true
wait(9)
ballClone:Destroy()
end
end)
I have another question. I had the bright idea to make the clones a kill brick, so you can use the friend as a weapon. When it spawns the clones, as it spawns them the exact same place as the real tool, it kills the player. I need to know how to make it so that it spawns the clones 5 studs away from the front of the player.