I, made a script where the player can attract coins after pressing a keybind but i want to be so that the attraction stops after a certain amount of time, how can i do this?
this is the script
function Magnetoid()
for _,c in pairs(game.Workspace.Coins:GetChildren()) do
if (c.Position - character.HumanoidRootPart.Position).Magnitude < 50 then
c.CanCollide = false
c.CFrame = c.CFrame:Lerp(character.HumanoidRootPart.CFrame , 0.325)
if (c.Position - character.HumanoidRootPart.Position).Magnitude <= 1 then
local tweenTransparency = tween_service:Create(c,
TweenInfo.new(0.5,Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut
),{
Transparency = 1
}
)
tweenTransparency:Play()
tweenTransparency.Completed:Wait()
game.Debris:AddItem(c,0.1)
end
end
end
end
UIS.InputBegan:Connect(function(Key,IsTyping)
if Key.KeyCode == Enum.KeyCode.Q then
--event:FireServer()
runservice.Heartbeat:Connect(function()
Magnetoid()
end)
end
end)