i tried some solutions and the same thing but something say NIL
here the script:
RunService.Stepped:Connect(function()
for _, Drop:Model in WorkspaceDrops:GetChildren() do
for i, Player in Players:GetChildren() do
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character and Drop and Drop.Parent ~= nil then
if (Character.PrimaryPart.Position - Drop.PrimaryPart.Position).Magnitude < 10 and Drop.CanCollect.Value == true then
if Character:WaitForChild("Humanoid").Health ~= 0 then
local ClickDetector:ClickDetector = Drop:WaitForChild("ClickDetector")
ClickDetector.MouseClick:Connect(function(player)
if not Debounces[Drop] then
Debounces[Drop] = true
ReplicatedStorage.Remotes.CollectDrop:Fire(Player,Drop.Name, false)
task.wait(3)
Debounces[Drop] = nil
end
ClickDetector:Destroy()
local CFrameTween = TweenService:Create(Drop.PrimaryPart,TweenInfo.new(1),{CFrame = CFrame.Angles(math.random(0,360), math.random(0,360), math.random(0,360))})
local SizeTween = TweenService:Create(Drop.PrimaryPart, TweenInfo.new(1), {Size = Vector3.new(0.001,0.001,0.001)})
local TransparencyTween = TweenService:Create(Drop.PrimaryPart, TweenInfo.new(1), {Transparency = 1})
CFrameTween:Play()
SizeTween:Play()
TransparencyTween:Play()
wait(3)
Drop:Remove()
wait(5)
Drop:Destroy()
end)
end
end
end
end
end
end)
please help idk what is happening please help
edit:
and last the remove then destroy is for after for no errors but doesn’t work
This is way too crammed together… making debugging very hard.
Try this … Also fully explain what you’re attempting to do here.
local rs = game:GetService("RunService")
local ts = game:GetService("TweenService")
local debounce = {}
local function createTweens(Drop)
local CFrameTween = ts:Create(Drop.PrimaryPart, TweenInfo.new(1), {CFrame = CFrame.Angles(math.random(0, 360), math.random(0, 360), math.random(0, 360)})
local SizeTween = ts:Create(Drop.PrimaryPart, TweenInfo.new(1), {Size = Vector3.new(0.001, 0.001, 0.001)})
local TransparencyTween = ts:Create(Drop.PrimaryPart, TweenInfo.new(1), {Transparency = 1})
CFrameTween:Play()
SizeTween:Play()
TransparencyTween:Play()
end
local function handleClick(player, Drop)
if not debounce[Drop] then
debounce[Drop] = true
game.ReplicatedStorage.Remotes.CollectDrop:Fire(player, Drop.Name, false)
task.wait(3)
debounce[Drop] = nil
end
Drop:Remove()
wait(5)
Drop:Destroy()
end
rs.Stepped:Connect(function()
for _, Drop in pairs(workspace.Drops:GetChildren()) do
for _, Player in pairs(game.Players:GetChildren()) do
local Character = Player.Character
if Character and Drop and Drop.Parent then
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid and Humanoid.Health > 0 then
local ClickDetector = Drop:FindFirstChild("ClickDetector")
if ClickDetector then
ClickDetector.MouseClick:Connect(function()
handleClick(Player, Drop)
end)
end
createTweens(Drop)
end
end
end
end
end)