local Ball = script.Parent
local BallTouchSettings = require(game.ReplicatedStorage.Settings)
local COOLDOWN = BallTouchSettings.COOLDOWN
local IMPULSE_FORCE = BallTouchSettings.IMPULSE_FORCE
local lastTouchTime = 0
local onCooldown = false
Ball.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not onCooldown then
local currentTime = tick()
if currentTime - lastTouchTime >= COOLDOWN then
local playerPosition = player.Character.HumanoidRootPart.Position
local direction = (Ball.Position - playerPosition).unit
Ball:ApplyImpulse(direction * IMPULSE_FORCE)
Ball.Velocity = Vector3.new()
lastTouchTime = currentTime
onCooldown = true
delay(COOLDOWN, function()
onCooldown = false
end)
end
end
end)
How can I improve this ball script? Right now I have a delay when touching the ball, and if the player stands on the ball, everything breaks down