Currently, this code will immediately collect the coins when in radius. However, i would like it to wait 2 seconds before allowing you to collect them. I Tried adding a task.wait(2) however it just made you wait 2 seconds to collect every individual coin. I added this just below the if drop.magnitude line. please help! Thanks.
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
while true do
for i, drop in pairs(workspace.Drops:GetChildren()) do
if drop:IsA("Part") and drop:FindFirstChild("Value") then
local magnitude = (HumanoidRootPart.Position - drop.Position).Magnitude
if magnitude <= player.Data.MagnetReach.Value then
local value = drop:WaitForChild("Value").Value
local CurrencyName = drop:WaitForChild("CurrencyName").Value
drop.CanCollide = false
local tween = ts:Create(drop, TweenInfo.new(magnitude * 0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = HumanoidRootPart.Position})
tween:Play()
tween.Completed:Connect(function()
rs:WaitForChild("GiveCurrency"):FireServer(CurrencyName, value)
drop:Destroy()
rs:WaitForChild("Sounds").Collect:Play()
end)
end
end
end
task.wait()
end
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
while true do
for i, drop in pairs(workspace.Drops:GetChildren()) do
if drop:IsA("Part") and drop:FindFirstChild("Value") then
local hyeah = tick()
local magnitude = (HumanoidRootPart.Position - drop.Position).Magnitude
if magnitude <= player.Data.MagnetReach.Value and tick() - hyeah >= 2 then
local value = drop:WaitForChild("Value").Value
local CurrencyName = drop:WaitForChild("CurrencyName").Value
drop.CanCollide = false
local tween = ts:Create(drop, TweenInfo.new(magnitude * 0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = HumanoidRootPart.Position})
tween:Play()
tween.Completed:Connect(function()
rs:WaitForChild("GiveCurrency"):FireServer(CurrencyName, value)
drop:Destroy()
rs:WaitForChild("Sounds").Collect:Play()
end)
end
end
end
task.wait()
end
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
while true do
for i, drop in pairs(workspace.Drops:GetChildren()) do
if drop:IsA("Part") and drop:FindFirstChild("Value") then
local hyeah = nil
if hyeah == nil then hyeah = tick() end
local magnitude = (HumanoidRootPart.Position - drop.Position).Magnitude
if magnitude <= player.Data.MagnetReach.Value and tick() - hyeah >= 2 then
local value = drop:WaitForChild("Value").Value
local CurrencyName = drop:WaitForChild("CurrencyName").Value
drop.CanCollide = false
local tween = ts:Create(drop, TweenInfo.new(magnitude * 0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = HumanoidRootPart.Position})
tween:Play()
tween.Completed:Connect(function()
rs:WaitForChild("GiveCurrency"):FireServer(CurrencyName, value)
drop:Destroy()
rs:WaitForChild("Sounds").Collect:Play()
end)
end
end
end
task.wait()
end
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
while true do
for i, drop in pairs(workspace.Drops:GetChildren()) do
if drop:IsA("Part") and drop:FindFirstChild("Value") then
local hyeah = nil
local magnitude = (HumanoidRootPart.Position - drop.Position).Magnitude
if hyeah == nil then hyeah = 0 end
if magnitude <= player.Data.MagnetReach.Value then hyeah +=.01
if hyeah >=2 then
hyeah = -math.huge -- bad coding lol
local value = drop:WaitForChild("Value").Value
local CurrencyName = drop:WaitForChild("CurrencyName").Value
drop.CanCollide = false
local tween = ts:Create(drop, TweenInfo.new(magnitude * 0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = HumanoidRootPart.Position})
tween:Play()
tween.Completed:Connect(function()
rs:WaitForChild("GiveCurrency"):FireServer(CurrencyName, value)
drop:Destroy()
rs:WaitForChild("Sounds").Collect:Play()
end)
else hyeah = nil -- correct this to make this set to nil if out of range.
end
end
end
task.wait()
end
end
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
while true do
for i, drop in pairs(workspace.Drops:GetChildren()) do
if drop:IsA("Part") and drop:FindFirstChild("Value") and not drop:FindFirstChild('ThisIsACooldownThing') then
local magnitude = (HumanoidRootPart.Position - drop.Position).Magnitude
if magnitude <= player.Data.MagnetReach.Value then
local value = drop:WaitForChild("Value").Value
local CurrencyName = drop:WaitForChild("CurrencyName").Value
drop.CanCollide = false
local tween = ts:Create(drop, TweenInfo.new(magnitude * 0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0), {Position = HumanoidRootPart.Position})
tween:Play()
tween.Completed:Connect(function()
rs:WaitForChild("GiveCurrency"):FireServer(CurrencyName, value)
drop:Destroy()
rs:WaitForChild("Sounds").Collect:Play()
end)
end
end
end
task.wait()
end
on the server you might wanna use debris to destroy the cooldown value