Tweening and BodyVelocity on Client

  1. What do you want to achieve? I want to be able to tween and add a BodyVelocity on the client to make it smoother

  2. What is the issue? Tweening works fine, but when I add the BodyVelocity, It doesn’t move because it Anchored, So I added a delay and then unanchor on the Server, but it falls because it’s Unanchored

  3. What solutions have you tried so far? Someone in Discord helped me, but it doesn’t seem like the solution has worked. He also told me to do .Touched on the server but it doesn’t detect anything except my character.

Client:

local function onActivated()
	--[[if os.clock() - last >= 4 then
		last = os.clock()
	end--]]
	
	for i = 1, 4 do
		local rockClone = RockFunction:InvokeServer()
		
		rockClone.Transparency = 0
		rockClone.Parent = workspace
		
		rockClone.Position = rootPart.Position + positions[i]

		local riseTweenInfo = TweenInfo.new(0.15, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
		local riseTween = TweenService:Create(rockClone, riseTweenInfo, {Position = rockClone.Position + Vector3.new(0, 17, 0)})
		riseTween:Play()
		
		riseTween.Completed:Wait()
		
		local lookAtTweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
		local lookAtTween = TweenService:Create(rockClone, lookAtTweenInfo, {CFrame = CFrame.lookAt(rockClone.Position, mouse.Hit.p)})
		lookAtTween:Play()
		
		lookAtTween.Completed:Wait()
		
		local target = mouse.Hit.p
		local timeOffset = (target - rockClone.Position).Magnitude * 0.005
	
		local hitTweenInfo = TweenInfo.new(timeOffset, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
		local hitTween = TweenService:Create(rockClone, hitTweenInfo, {Position = target})
		hitTween:Play()
		
		--[[local Velocity = Instance.new("BodyVelocity")
		Velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		Velocity.Velocity = rockClone.CFrame.LookVector * 150
		Velocity.Parent = rockClone--]]
	end
end

Server:

RockFunction.OnServerInvoke = function(player)
	local rockClone = workspace.Rock:Clone()
	rockClone.Parent = workspace.MovingRocks
	rockClone.Transparency = 1
	
	task.delay(0.6, function()
		rockClone.Anchored = false
	end)
	
	rockClone.Touched:Connect(function(hit)
		print(hit.Parent) --Everything is descendant of my Character
	end)
	
	return rockClone
end

Why do you want to add a BodyVelocity?

I want it to work as a bullet, if I use a tween, it would stop after a certain position.

Calculate the tween distance. Similar to

local Speed = 100 -- Stud per seconds
local TimeDebris = 1 -- Time remain

local DistanceToTravel = Speed * TimeDebris

local BulletTween = TweenService:Create(
   Bullet,
   TweenInfo.new(TimeDebris),
   {
      ["CFrame"] = Bullet.CFrame * CFrame.new(0, 0, -DistanceToTravel)
   }
)

You could’ve just anchor it when it is tweening, once all the tweens are done unanchor it and immediately add the BodyVelocity.

I did that on the client but it doesn’t work, also tried adding a delay before I unanchor on the server.

I’ll try this later, but I’m not sure if it will act as a bullet.

This works now but my collision detection is still not working, thanks for the help though.

Hello there.

If you want to move something via client you need to two 1 of two things.

  1. Make sure the thing that you want to move is part of your character.

The only thing by default replicated without any interference is the character. So making sure the part or model is part of your character will give the client full control

  1. Set network ownership to player.

For other cases you can change the baseparts network ownership to the player.

My advice would be to set the network ownership to the player. Then on the client anchor and tween and then wait for the tween to end. Finally unanchor and then body velocity.

RockFunction.OnServerInvoke = function(player)
	local rockClone = workspace.Rock:Clone()
	rockClone.Parent = workspace.MovingRocks
	rockClone.Transparency = 1
	
	rockClone:SetNetworkOwner(player)
	
	rockClone.Touched:Connect(function(hit)
		print(hit.Parent) --Everything is descendant of my Character
	end)
	
	return rockClone
end

Ok, I’ll try. But how does the making the rock a descendant of the character gonna give the client full control?

The client has full physical ownership of his character model by default. So the client is able to easily move and animate his or her character without any delay. We can exploit this by simply parenting and part we want to control client sided to the player.

There is a few exceptions though. The client can’t add anything to his own character. Anything that is created client side will always stay client side even if it is a part of their character. So you have to make the part server side and then parent the part to the character.

I recommend the second way using the SetNetworkOwner() Method.

This is a brilliant tutorial on how it can be applied in a script. The 3rd problem is the one you want to look at.

I actually made a place where you can see what happens.

Network ownership is allocated to players to lessen the impact of physics on the server

https://gyazo.com/29b4ccdc198934ea327ea561f3661b70

https://gyazo.com/c2d3c990b87391c16626492601d8600d

I don’t know if it is clear but when I move closer to the ball the clients takes physical control of the ball then it starts moving forward. As the ball leaves the clients control the server retakes control and the ball stops rolling

1 Like

It’s fixed now, the problem is it doesn’t get replicated to other clients. I might post another topic on how to fix it.