How to make an object follow a certain player?

deadlift.OnServerEvent:Connect(function(Player, barOccupied)
	local minimum = 10
	local bar = game.Workspace["Phase 1"].GymEquipment.Benchpress.deadlift_barbell.BenchpressBar
	local weight1 = game.Workspace["Phase 1"].GymEquipment.Benchpress.deadlift_barbell.fortyFive
	local weight2 = game.Workspace["Phase 1"].GymEquipment.Benchpress.deadlift_barbell.fortyFive2
	local owner = Player.Owner
	
	if Player.leaderstats.Energy.Value > 0 and Player.leaderstats.Energy.Value >= minimum then
		Player.leaderstats.Energy.Value -= 10
		Player.leaderstats.Strength.Value += 10
		
		RunService.Heartbeat:Connect(function()
			if barOccupied.Value == true and owner.Value == true then
				bar.Position = (Player.Character.LeftHand.Position + Player.Character.RightHand.Position) / 2
				print(Player.Name)
				weight1.Position = bar.Position + Vector3.new(-2.85,0,0)
				weight2.Position = bar.Position + Vector3.new(2.85,0,0)
			end
		end)
		
	end
end)

(Server script)
The bar is following the first player who gets on and also the second player at the same time even when the first player is off the bar.

How can I get the object to follow only the player who is using the bar?

#Edit
Here’s what’s happening, when Player1 hops on the deadlift bar by pressing F, the deadlift bar follows Player1’s hands. Then when Player2 gets on the bar, the bar goes back and follows Player1’s hands. How can I make it to where the bar follows the player’s hands only when they are on the deadlift?

Use a RocketPropulsion Instance, and on your server side part you would need to set the Target, then you use :Fire() after you set the target.

Not sure if this is what you’re looking for.

1 Like

Sorry for not explaining my question thoroughly. Here’s what’s happening, when Player1 hops on the deadlift bar by pressing F, the deadlift bar follows Player1’s hands. Then when Player2 gets on the bar, the bar goes back and follows Player1’s hands. How can I make it to where the bar follows the player’s hands only when they are on the deadlift?

How does the script detect who pressed the button? Try to print the name of the player that is pressing the button, if it does not change then the problem is in another script
Also use print(player.Name) in this script to check also there