Raycast fast movement bug

When I move the mouse fast, the anchored character fly to high and don’t return.

...
local RP = RaycastParams.new()
RP.FilterType = Enum.RaycastFilterType.Include
RP.FilterDescendantsInstances = {workspace.MAP}
Raycast = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction.Unit * 500, RP)
	if Raycast ~= nil then
	print(Raycast.Position)
	Character:MoveTo(Raycast.Position)
...
1 Like

can you send the whole script? i dont see any problems from just this bit, maybe its soemthign else

local plr = game.Players.LocalPlayer
local CS = game:GetService('CollectionService')
local UIS = game:GetService('UserInputService')
for _, v in pairs(script.Parent:GetChildren()) do
	if v:IsA('Frame') then
		CS:AddTag(v.Button, 'Button')
	end
end

local Buttons = CS:GetTagged('Button')
local Raycast

for _, v in pairs(Buttons) do
	v.MouseButton1Click:Connect(function()
		local ActualCharacter
		local Character = v.Parent.CharacterFace:WaitForChild('Appearance'):Clone()
		Character.HumanoidRootPart.Anchored = true
		Character.Parent = workspace.MouseIgnore
		Character.Range.Transparency = 0
		Character.Range.Area.Decal.Transparency = 0
		local Unit = plr.Units[v.Parent.Name]
		local Type = Unit.Type.Value
		local mouse = plr:GetMouse()

		local move = game:GetService('RunService').RenderStepped:Connect(function()
			local RP = RaycastParams.new()
			RP.FilterType = Enum.RaycastFilterType.Include
			RP.FilterDescendantsInstances = {workspace.MAP}
			Raycast = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction.Unit * 500, RP)
			if Raycast ~= nil then
				print(Raycast.Position)
				Character:MoveTo(Raycast.Position)
				local Ground = false
				local DontColliding = true

				local op = OverlapParams.new()
				op.FilterType = Enum.RaycastFilterType.Include
				op.FilterDescendantsInstances = workspace.MouseIgnore:GetDescendants()
				op.RespectCanCollide = false
				for _, v in pairs(workspace.MouseIgnore.Areas[Type]:GetChildren()) do
					v.Transparency = 0.8
				end
				for _, v in pairs(workspace:GetPartsInPart(Character.TouchArea, op)) do
					if Type == 'Air' then
						if v.Name == 'AirArea' and v.Parent.Parent == workspace.MouseIgnore.Areas then
							Ground = true
						elseif v.Name == 'TouchArea' then
							DontColliding = false
						end
					else
						if v.Name == 'GroundArea' and v.Parent.Parent == workspace.MouseIgnore.Areas then
							Ground = true
						elseif v.Name == 'TouchArea' then
							DontColliding = false
						end
					end
				end

				if Ground == true and DontColliding == true then
					Character.Range.BrickColor = BrickColor.new('Lime green')
				else
					Character.Range.BrickColor = BrickColor.new('Really red')
				end
			end
		end)
		local click
		local F
		click = mouse.Button1Down:Connect(function()
			if Raycast ~= nil then
				Raycast = nil
				move:Disconnect()
				game.ReplicatedStorage.PutUnit:FireServer(v.Parent.Name, Raycast.Position)
				Character:Destroy()
				click:Disconnect()
				F:Disconnect()

				for _, v in pairs(workspace.MouseIgnore.Areas[Type]:GetChildren()) do
					v.Transparency = 1
				end
			end
		end)
		F = UIS.InputBegan:Connect(function(key)
			if key.KeyCode == Enum.KeyCode.F then
				click:Disconnect()
				move:Disconnect()
				Character:Destroy()
				for _, v in pairs(workspace.MouseIgnore.Areas[Type]:GetChildren()) do
					v.Transparency = 1
				end
				F:Disconnect()
			end
		end)
	end)
end```

You are here guy? I need help, this is the worst error in my game and that will disturb my script.

Ok, I discover the reason, after a few seconds the character jump for no reason.