Body Velocity Problem

  1. What do you want to achieve? Keep it simple and clear!
    i am trying to make a beyblade system and it seems to be working but its acting weird
  2. What is the issue? Include screenshots / videos if possible!
    my beyblade keeps teleporting after it starts gaining speed, here is a video of the problem
    https://gyazo.com/dc6be40148b7020fa98cccbf9ce30049

if i move it around for around 30 seconds the problem fixes its self but i dont want players to have to do that in order to use there beyblade

here is my code

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local char = game.Workspace:WaitForChild(player.Name)
local hum = char:WaitForChild("Humanoid")

local executedKill = false


local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local remote = script.Parent:WaitForChild("remote")
local killBey = false
--bey
local bey = workspace:WaitForChild(player.Name.."s Bey").Beyblade
local beyVel = bey:WaitForChild("beyVel")
local beyGyro = bey:WaitForChild("beyGyro")
local beyWeld = bey:WaitForChild("beyWeld")
local beyHealth = bey:WaitForChild("beyHealth")
local beyMaxHealth = bey:WaitForChild("beyMaxHealth")
local isHeavyHitting = bey:WaitForChild("heavyAttack")
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = bey
local cam = game.Workspace.CurrentCamera
local i = 1
local typing = false

local forward = false
local backward = false
local left = false
local right = false

local forwardAcceleration = 0.0
local leftAcceleration = 0.0
local maxAcceleration = 9.0
local accelerationDelta = 0.35

local canJump = true
local jumpCD = 0
local jumpCDMax = 180

local previousTilt = CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
local cI = 0.0



local fakeP = Instance.new("Part", game.Workspace)
fakeP.Anchored = true
fakeP.Size = Vector3.new(.3,.3,.3)
fakeP.CanCollide = false
fakeP.Massless = true
fakeP.BrickColor = BrickColor.new("Really red")
fakeP.Transparency = 1


--functionality
UIS.TextBoxFocused:connect(function()
	typing = true
end)
UIS.TextBoxFocusReleased:connect(function()
	typing = false
end)
UIS.InputBegan:connect(function(input, istyping)
	if istyping then return end
		local key = input.KeyCode
		if key == Enum.KeyCode.W then
			forward = true
			backward = false
		elseif key == Enum.KeyCode.S then
			backward = true
			forward = false
		elseif key == Enum.KeyCode.A then
			left = true
			right = false
		elseif key == Enum.KeyCode.D then
			right = true
			left = false
		elseif key == Enum.KeyCode.Space or key == Enum.KeyCode.ButtonA then
			if canJump == true then
				canJump = false
				jumpCD = jumpCDMax
				bey.Velocity = Vector3.new(0, 35, 0)
			end
		end
end)

UIS.InputEnded:connect(function(input, istyping)
	if istyping then return end
	local key = input.KeyCode
	if key == Enum.KeyCode.W then
		forward = false
	elseif key == Enum.KeyCode.S then
		backward = false
	elseif key == Enum.KeyCode.A then
		left = false
	elseif key == Enum.KeyCode.D then
		right = false
	end
end)


lerp = function(start, goal, alpha)
	return start + (goal - start) * alpha
end
isRealNumber = function(num)
	return (typeof(num) == "number") and (num == num) and (math.abs(num) ~= math.huge)
end
calculateMovement = function()
	--pc
	if left == true then
		if leftAcceleration > -maxAcceleration then
			leftAcceleration = leftAcceleration - accelerationDelta
		end	
	elseif right == true then
		if leftAcceleration < maxAcceleration then
			leftAcceleration = leftAcceleration + accelerationDelta
		end
	end
	if forward == true then
		if forwardAcceleration > -maxAcceleration then
			forwardAcceleration = forwardAcceleration - accelerationDelta
		end
	elseif backward == true then
		if forwardAcceleration < maxAcceleration then
			forwardAcceleration = forwardAcceleration + accelerationDelta
		end
	end
	--revert back to center
	if forward == false and backward == false then
		forwardAcceleration = lerp(forwardAcceleration, 0, .04)
	end
	if left == false and right == false then
		leftAcceleration = lerp(leftAcceleration, 0, .04)
	end
end
local calculateTilt = function()
	if forward == true and left == true then
		--W AND A
		return CFrame.Angles(math.rad(-15), 0, math.rad(15))
	elseif forward == true and right == true then
		--W AND D
		return CFrame.Angles(math.rad(-15), 0, math.rad(-15))
	elseif backward == true and left == true then
		--S AND A
		return CFrame.Angles(math.rad(15), 0, math.rad(15))
	elseif backward == true and right == true then
		--S AND D
		return CFrame.Angles(math.rad(15), 0, math.rad(-15))
	elseif forward == true and left == false and right == false then
		--JUST W
		return CFrame.Angles(math.rad(-15), 0, 0)
	elseif backward == true and left == false and right == false then
		--JUST S
		return CFrame.Angles(math.rad(15), 0, 0)
	elseif left == true and forward == false and backward == false then
		--JUST A
		return CFrame.Angles(math.rad(0), 0, math.rad(15))
	elseif right == true and forward == false and backward == false then
		--JUST D
		return CFrame.Angles(math.rad(0), 0, math.rad(-15))
		end
	return CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
end

resetBey = function()
	cam.CameraSubject = char.Humanoid
	executedKill = true
	beyGyro:Destroy()
	beyVel:Destroy()
	killBey = true
	beyVel.Velocity = Vector3.new(0, 0, 0) 
end
killTheBey = function()	
	if executedKill == false then
		if beyHealth.Value <  -45 then
			resetBey()
		else
			wait(5)
			resetBey()
		end
	end
end
--runtime
game:GetService("RunService").RenderStepped:connect(function()
	if beyHealth.Value < 1 or killBey == true then
		beyVel.Velocity = Vector3.new(0, 0, 0) 
		killTheBey()
	else
		
		i = i + 1
		--wobbleRot = wobbleRot + wobble math.rad((wobbleRot*.1)*15
		cI = cI + -.35
		local beyPercent = ((beyHealth.Value/beyMaxHealth.Value))
		if beyPercent < 0.5 then
			local wobbleViscosity = (1-(1*beyPercent))*.4
			beyWeld.C1 =  CFrame.fromEulerAnglesXYZ(0, cI*(.5+beyPercent), 0) * CFrame.Angles(math.sin(tick()*5)*wobbleViscosity, 0, math.cos(tick()*5)*wobbleViscosity)
		else
			beyWeld.C1 =  CFrame.fromEulerAnglesXYZ(0, cI, 0)
		end
		if beyHealth.Value < 1 or char.Humanoid.Health < 1 then
			killTheBey()
		end
		local camLV = cam.CFrame.LookVector
		local flat = Vector3.new(camLV.X, 0, camLV.Z)
		local beyCF = bey.CFrame.p
		local turnRot = CFrame.new(beyCF, beyCF + flat)
		previousTilt = previousTilt:Lerp(calculateTilt(), .1)--goal, alpha
		beyGyro.CFrame = turnRot * previousTilt
		calculateMovement()
		fakeP.CFrame = turnRot*CFrame.new(leftAcceleration, 0, forwardAcceleration)
		local speedDistance = (bey.Position - fakeP.Position).magnitude
		local speed = CFrame.new(turnRot.p, fakeP.CFrame.p).lookVector*(speedDistance*3)
		if beyVel:WaitForChild("disabled").Value == false then
			if isRealNumber(speed.X) == true or isRealNumber(speed.Z) == true then
				if beyPercent < 0.4 then
					beyVel.Velocity = speed * (beyPercent+.3)
				else
					beyVel.Velocity = speed
				end
				if isHeavyHitting.Value == true then
					beyVel.Velocity = beyVel.Velocity * 2
				end
			else
				beyVel.Velocity = Vector3.new(0, 0, 0) 
			end
		else
			--disabled
		end


		if jumpCD > 1 then
			jumpCD = jumpCD - 1
			if jumpCD < 2 then
				canJump = true
			end
		end
	end
end)

if your able to help me solve this please do

it looks like a network ownership problem make sure to set the beyblade network owner to the client who is controlling it you can read more about it here Network Ownership

another note is BodyVelocity has been deprecated

you should be using LinearVelocity instead

ty for the reply ill try this and see if it fixes my problem

thank you yes that fixed my issue also i switched my body velocity to linear velocity like u suggested

1 Like