Give this a go
local replicatedStorage = game:GetService("ReplicatedStorage")
local gun = replicatedStorage:WaitForChild("MK-18")
local gunSpawn = workspace.Spawners:WaitForChild("Spawn")
local spawned = false
while wait(5) do
if spawned then
spawned = false
if gunSpawn:FindFirstChild(gun.Name) then
gunSpawn[gun.Name]:Destroy()
end
else
spawned = true
local gunClone = gun:Clone()
gunClone.Parent = gunSpawn
end
end
Your gun would get deleted instantly
its fixed now, i got a question on how you can use
while true do
Nvm, I couldnât read. But there is no point of adding 2 waits and checking if gun is a gun spawn.
ayoub50
(Ayoub)
August 17, 2022, 11:09pm
#26
while true do loop will always run cuz the âtrueâ will be always âtrueâ
for example you can do smth else by :
local Test = true
while Test do -- while Test is true
end
1 Like
while true do is a infinite loop. Anything in that loop would run indefinitely unless there is a yield.
1 Like
Also the if statement checking if the gun is the spawner is completely useless and you can simply use :Destroy instead of using debris service.
Alright, well thank you all so much for you help guys, i really apperciate it!
1 Like
ayoub50
(Ayoub)
August 17, 2022, 11:11pm
#30
no, debris is a better alternative way than :Destroy()
Not in this situation. Youâre not using debris to delete something after x amount of seconds so delete would be more useful.
ayoub50
(Ayoub)
August 17, 2022, 11:13pm
#32
that if statement isnât useless, cuz if we remove that statement the gun will get removed from the playerâs character/backpack or anywhere else.
You should use :Destroy this situation and debris service when you have to deal something like
coroutine.wrap(function()
wait(5)
instance:Destroy()
end)()
Why are you also cloning the gunSpawn tho?
I fixed that issue, dont worry lol
ayoub50
(Ayoub)
August 17, 2022, 11:16pm
#36
there is no such a thing called Delete, and up there you said :Destroy not :Delete()
also up there you mentioned :Destroy() Not :Delete()
Sorry im making typos but you get my point
ayoub50
(Ayoub)
August 17, 2022, 11:17pm
#38
Cloning the Spawner from ReplicatedStorage.
GunSpawn is in workspace not replicated storage
ayoub50
(Ayoub)
August 17, 2022, 11:18pm
#40
oh ye, just realised that lol, removed the clone.
Lol, so the clone isnt necessary.