Player moves after setting walkspeed to 0 and removing velocity

If I am running forward and throw my frisbee, it spawns behind me and hits me in the back. I try to make it spawn 5 studs in front of me. You can see the 4 times I print a message and this is what I get:
22:07:47.368 80.41546630859375, 3.679743766784668, 339.53314208984375 - Server - Frisbee Script:138
22:07:47.368 80.4154663, 3.67974377, 339.533142, 1, 0, 0, 0, 1, 0, 0, 0, 1 - Server - Neer Frisbee Script:144
22:07:47.668 85.4154663, 3.99699998, 339.533142, 1, 0, 0, 0, 1, 0, 0, 0, 1 - Server - Frisbee Script:216
22:07:47.668 88.86921691894531, 3.679743766784668, 339.8255310058594 - Server - Frisbee Script:217

The first 3 CFrames are what I expect, but the last one shows that the player has moved beyond the spawn position. In this case, I only want the frisbee to travel in the positive X direction.

function shot(direction)
	brake=true
	animationInProgress=true
	
	local directionMultiplier=1
	local vectorForceApplied=0
	
	
	
	local character=frisbee.Parent
	
	character:WaitForChild("Humanoid").WalkSpeed=0
	character.PrimaryPart.AssemblyLinearVelocity = Vector3.zero
	character.PrimaryPart.AssemblyAngularVelocity = Vector3.zero 
	
	
	print(character:WaitForChild("HumanoidRootPart").CFrame.Position)
	
	local player= game.Players:GetPlayerFromCharacter(character)
	local humanoid=character:FindFirstChild('Humanoid')
	local spawnPos = CFrame.new(character:WaitForChild("HumanoidRootPart").CFrame.Position)
	
	print(spawnPos)
	
	--find target point
	local mouseHit = game.ReplicatedStorage.getMouseLocation:InvokeClient(player)
	local angle=math.atan((mouseHit.Z-spawnPos.Z)/(mouseHit.X-spawnPos.X))

	local x=math.cos(angle)
	local z=math.sin(angle)
	--print(math.deg(angle))
	
	--determine power level
	if bluePerfects==3 and b==-1 or redPerfects==3 and b==1 then
		x=x*300
		z=z*300

		if b==1 then
			redPerfects=0
		elseif b==-1 then

			bluePerfects=0
		end

	elseif timer<.1 then
		x=x*blue
		z=z*blue
		keypoints=greyKeypoints
		print("early")
	elseif timer<purpleWindow then	
		x=x*purple-((.1/timer)*50)
		z=z*purple-((.1/timer)*50)
		keypoints=purpleKeypoints

		if b==1 then
			redPerfects+=1	
			shotFeedback(redPerfects)

		elseif b==-1 then

			bluePerfects+=1	
			shotFeedback(bluePerfects)

		end

	elseif timer <blueWindow then
		print("bluex="..x)
		x=x*blue-((purpleWindow/timer)*35)
		z=z*blue-((purpleWindow/timer)*35)
		keypoints=blueKeypoints

	elseif timer<grayWindow then
		x=x*gray-((blueWindow/timer)*20)
		z=z*gray-((blueWindow/timer)*20)
		keypoints=greyKeypoints

	else
		x=x*50
		z=z*50
		keypoints=greyKeypoints
	end

	--print("timer=" ..timer)
	playAnimation(character)
	wait(.25)
	mesh:Destroy()
	if intermediate then
		intermediate:Destroy()
	end
	
	--set velocity
	frisbee.Parent=game.Workspace
	frisbee.Handle.CFrame=CFrame.new(spawnPos.X+(b*5),3.997,spawnPos.Z)
	frisbee.Handle.AssemblyLinearVelocity=Vector3.new(x*b,0,z*b)
	print(CFrame.new(spawnPos.X+(b*5),3.997,spawnPos.Z))
	print(character:WaitForChild("HumanoidRootPart").CFrame.Position)
	--print("x="..x)
	--print("z="..z)

	--Curve
	
	
	if direction=="right" or direction=="left"then 
		
		if direction=="right" then
			directionMultiplier=-1
		end
		vectorForceApplied=-1*directionMultiplier*b*math.abs(math.deg(angle)*20)
		if math.abs(vectorForceApplied)>maxVectorForce then
		vectorForceApplied=-maxVectorForce*b
		end
	vectorForce.Force=Vector3.new(0,0,vectorForceApplied)
	vectorForce.Enabled = true
		print("vector force="..vectorForceApplied)
		
		
		end
--intermediate
	intermediate=Instance.new("Part")
	intermediate.Name="Intermediate"
	intermediate.Parent=body
	intermediate.CFrame=body.CFrame
	if direction=="right" or direction=="left"then
		intermediate.Orientation=Vector3.new((vectorForceApplied/maxVectorForce)*45,0,0)
	else
		intermediate.Orientation=Vector3.new(0,0,0)
	end


	local weld = Instance.new("WeldConstraint")
	weld.Parent = intermediate
	weld.Part0 = body
	weld.Part1 = intermediate

	intermediate.Transparency=1
	intermediate.CanTouch=false
	intermediate.CanCollide=false
	intermediate.Massless=true

	local rotationAttachment=Instance.new("Attachment")
	rotationAttachment.Name="RotationAttachment"
	rotationAttachment.Parent=intermediate
	rotationAttachment.Orientation=Vector3.new(0,180,90)






	--apply frisbee skin
	mesh=game.ReplicatedStorage.Frisbees.tronfrisbee:Clone()
	mesh.CustomPhysicalProperties=PhysicalProperties.new(.1,0,0)
	mesh.CanTouch=false
	mesh.CanCollide=false
	mesh.Massless=true
	--mesh:MoveTo(intermediate.Position)
	mesh.Position=intermediate.Position
	mesh.Size=Vector3.new(5,5,1)
	--mesh.Scale=1
	mesh.Parent=body


	local hinge = Instance.new("HingeConstraint")
	hinge.Parent = intermediate
	hinge.Attachment0 = rotationAttachment
	--	hinge.Attachment1 = mesh.Attachment
	hinge.Attachment1 = mesh:FindFirstChildOfClass("Attachment")

	hinge.ActuatorType="Motor"
	hinge.AngularVelocity=-15*b
	hinge.MotorMaxAcceleration=15
	hinge.MotorMaxTorque=15
	
	
	--stop spin
	frisbee.Handle.AlignOrientation.Enabled=true

	--set network ownership
	for i,v in pairs(frisbee:GetDescendants()) do
		if v:IsA("BasePart") then
			v:SetNetworkOwner(nil)
		end
	end
	
	
	--Trail
	--(0,0,+-2.5)
	local trailAttachment1=Instance.new('Attachment')
	local trailAttachment2=Instance.new('Attachment')
	trailAttachment1.Parent=intermediate
	trailAttachment2.Parent=intermediate
	trailAttachment1.Position=Vector3.new(0,0,2.5)
	trailAttachment2.Position=Vector3.new(0,0,-2.5)
	trail.Attachment0=trailAttachment1
	trail.Attachment1=trailAttachment2

	trail.Enabled=true
	trail.Color= ColorSequence.new(keypoints)
	if keypoints==purpleKeypoints then
		trail.Lifetime=.5
	else 
		trail.Lifetime=.3
	end
	
	--Set collision group
	frisbee.Handle.Body.CollisionGroup='frisbee'
	for _, v in pairs(character:GetChildren()) do
		if v:IsA("Basepart") then
			v.CollisionGroup = "None"
		end
	end
	frisbee.Handle.Body.CanTouch=false
	frisbee.Handle.CanTouch=false
	wait(.3)
	for _, v in pairs(character:GetChildren()) do
		if v:IsA("Basepart") then
			v.CollisionGroup = "Default"
		end
	end
	frisbee.Handle.Body.CanTouch=true
	frisbee.Handle.CanTouch=true
	


	
	character:WaitForChild("Humanoid").WalkSpeed=40
	animationInProgress=false
end

You can always spawn it ahead by adding the x-axis velocity of the player onto the spawn position, and then add an offset onto that just in case.

I don’t want the player to be able to move while throwing the frisbee. I tried this anyway, but by the time the script reaches the line to set the frsibee’s velocity, the player’s velocity is close to 0 so the frisbee still spawns behind.

1 Like