I have a ball that you can launch using a 3D Gui element, the ball is launched when the “launch” button is pressed. Here is the remote event fired when the button is activated.
local rS = game:GetService("ReplicatedStorage")
local fireEvent = rS:FindFirstChild("BallFire")
local bodyGyr = game.Workspace.Part.BodyGyro
local bodyFor = game.Workspace.Part.BodyForce
fireEvent.OnServerEvent:Connect(function(player, Vector, velocity)
print("fired!")
print(player)
print(Vector)
bodyFor.Parent.Anchored = false
bodyGyr.CFrame = bodyFor.Parent.CFrame
print(velocity)
bodyFor.Force = Vector3.new(-Vector.x * velocity*3, -Vector.y * velocity*3, -Vector.z * velocity*3)
wait(0.1)
bodyFor.Force = Vector3.new(0, 0, 0)
end)
Then, if the player wants to refire the ball, there is a cancel button that resets the position and anchors it again.
local rS = game:GetService("ReplicatedStorage")
local fireEvent = rS:FindFirstChild("ResetFire")
local ball = game.Workspace.Part
local ballPos = ball.Position
fireEvent.OnServerEvent:Connect(function(player)
ball.Position = ballPos
ball.Anchored = true
game.Workspace.arrow.Position = ballPos
print("reset")
buul.Value = false
end)
The problem is when the ball is fired next, the ball’s velocity from when the player hit reset compounds with the new velocity and direction they have already chose.
https://gyazo.com/7dca54bff3e331b928ab5c10e3d22358
Does anyone know how to fix this?