Part Doesn't stop moving after applyimulse

Hello! I used apply impulse, but when it was applied the part didn’t stop moving for some reason. It might have something to do with friction, but I’m not sure. Here’s my code:

uis.InputBegan:Connect(function(inpt, gpe)

	
	if inpt.UserInputType == Enum.UserInputType.MouseButton1 then
		local hitbox = game.ReplicatedStorage.Hitbox:Clone()
		hitbox.Parent = workspace
		hitbox.Position = plr.Character.HumanoidRootPart.Position
		hitbox.WeldConstraint.Part0 = plr.Character.HumanoidRootPart
		
		local params = OverlapParams.new()
		params.CollisionGroup = "Ball"
		local partsinbound = workspace:GetPartsInPart(hitbox, params)
		game.Debris:AddItem(hitbox, 0.3)
		for i,v: Part in pairs(partsinbound) do 
			print(v)
			if v.Name == "Ball" then
				game.ReplicatedStorage.Kickrem:FireServer(v)
				repeat
					task.wait()
				until v:GetAttribute("Owner") == plr.Name
			v:ApplyImpulse(plr.Character.HumanoidRootPart.CFrame.LookVector * 10)
				
			
			end
		end
	end
	
	
end)
2 Likes

You are applying it using CFrame.LookVector * 10 which moves the part in the direction of the humanoid root part infinitely. You need to set the goal position to where you want it to go, not infinitely.

1 Like

How would i go about doing that?

1 Like

Where do you want the part to go?

1 Like

A little bit forward from the lookvector

1 Like
uis.InputBegan:Connect(function(inpt, gpe)

	
	if inpt.UserInputType == Enum.UserInputType.MouseButton1 then
		local hitbox = game.ReplicatedStorage.Hitbox:Clone()
                local Value = 10
		hitbox.Parent = workspace
		hitbox.Position = plr.Character.HumanoidRootPart.Position
		hitbox.WeldConstraint.Part0 = plr.Character.HumanoidRootPart
		
		local params = OverlapParams.new()
		params.CollisionGroup = "Ball"
		local partsinbound = workspace:GetPartsInPart(hitbox, params)
		game.Debris:AddItem(hitbox, 0.3)
		for i,v: Part in pairs(partsinbound) do 
			print(v)
			if v.Name == "Ball" then
				game.ReplicatedStorage.Kickrem:FireServer(v)
				repeat
					task.wait()
				until v:GetAttribute("Owner") == plr.Name
                        coroutine.wrap(function()
                        for i=1, 10 do
                        Value = Value - 1
                        task.wait()
			v:ApplyImpulse(plr.Character.HumanoidRootPart.CFrame.LookVector * Value)
                        end
                        end)()
                       
				
			
			end
		end
	end
	
	
end)
1 Like

I don’t want to anchor it though because it’s a kicking ball

2 Likes

So use the code I just gave you and whatever your entire script looks like just throw the value all the way at the top instead of inside the input and set it to 10 and then reset it to 10 at the end of every time it does that so you can keep repeatedly moving the ball that distance

1 Like

I still want it to stop though, just gradually

1 Like

the issue you were facing was that after applying an impluse to the ball it’s because lack of friction and air resistance in the game physics we can add a physical simulation

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")

local player = Players.LocalPlayer

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        local hitbox = ReplicatedStorage.Hitbox:Clone()
        hitbox.Parent = workspace
        hitbox.Position = player.Character.HumanoidRootPart.Position
        hitbox.WeldConstraint.Part0 = player.Character.HumanoidRootPart
        
        local params = OverlapParams.new()
        params.CollisionGroup = "Ball"
        local partsInBound = workspace:GetPartsInPart(hitbox, params)
        Debris:AddItem(hitbox, 0.3)
        
        for _, v in pairs(partsInBound) do 
            if v:IsA("Part") and v.Name == "Ball" then
                ReplicatedStorage.Kickrem:FireServer(v)
                repeat task.wait() until v:GetAttribute("Owner") == player.Name
                
                local kickForce = player.Character.HumanoidRootPart.CFrame.LookVector * 500
                v:ApplyImpulse(kickForce)
                
                v.CustomPhysicalProperties = PhysicalProperties.new(0.7, 0.3, 0.5, 1, 0)
                
                task.spawn(function()
                    local dragMultiplier = 0.99
                    while v.Velocity.Magnitude > 0.1 do
                        v.Velocity = v.Velocity * dragMultiplier
                        task.wait(0.1)
                    end
                    v.Velocity = Vector3.new(0, 0, 0)
                end)
            end
        end
    end
end)
2 Likes

The ball still continues infinitely though

1 Like

Actually it does kind of work but when I hit the ball repeatedly it stops abruptly

1 Like

try this i updated the code

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer

local function applyDragForce(ball)
    local connection
    local lastKickTime = 0
    connection = RunService.Heartbeat:Connect(function(dt)
        if not ball or not ball.Parent then
            connection:Disconnect()
            return
        end
        
        local currentTime = tick()
        if currentTime - lastKickTime < 0.5 then
            return
        end
        
        local velocity = ball.Velocity
        local dragForce = -velocity.Unit * velocity.Magnitude^2 * 0.05
        ball.Velocity = ball.Velocity + dragForce * dt
        
        if velocity.Magnitude < 0.5 then
            ball.Velocity = Vector3.new(0, 0, 0)
            connection:Disconnect()
        end
    end)
    
    return function()
        lastKickTime = tick()
    end
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        local hitbox = ReplicatedStorage.Hitbox:Clone()
        hitbox.Parent = workspace
        hitbox.Position = player.Character.HumanoidRootPart.Position
        hitbox.WeldConstraint.Part0 = player.Character.HumanoidRootPart
        
        local params = OverlapParams.new()
        params.CollisionGroup = "Ball"
        local partsInBound = workspace:GetPartsInPart(hitbox, params)
        game.Debris:AddItem(hitbox, 0.3)
        
        for _, v in pairs(partsInBound) do 
            if v:IsA("Part") and v.Name == "Ball" then
                ReplicatedStorage.Kickrem:FireServer(v)
                repeat task.wait() until v:GetAttribute("Owner") == player.Name
                
                local kickForce = player.Character.HumanoidRootPart.CFrame.LookVector * 50
                v:ApplyImpulse(kickForce)
                
                v.CustomPhysicalProperties = PhysicalProperties.new(0.7, 0.3, 0.5, 1, 0)
                
                local updateLastKickTime = applyDragForce(v)
                updateLastKickTime()
            end
        end
    end
end)
2 Likes

The issue still occurs; it stops very abruptly

1 Like

It could have something to do with my collision groups but I’m not sure

1 Like

I give mythical credit where credit is due. He is blindly helping you with this. It’s incredibly difficult to help you here without seeing all of the scripts but besides that I can definitely say for a fact that it stopping abruptly should have something to do with the connection:Disconnect and/or the velocity being set the Vector3.new(0, 0, 0). Try removing those things and see what happens.

2 Likes

I switched back to his old code and tweaked/added some things so that dribbling is possible but when you try to change direction it bugs out

2 Likes

Oh yeah theres a server script that sets network ownership and a justhit value but that’s about it

3 Likes

If you could please send us the entire thing that would be wonderful. Doesn’t even have to be exact. Just a file with the stuff you want help with and you can change it to be different if you don’t want us to see your original creations. I am sure he can help you in a matter of minutes when seeing the entire thing

2 Likes

That could definitely explain why it bugs out. Network ownership is important and needs to be done correctly

2 Likes