Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Help with hovering/flying?

Asked by 9 years ago

Im working on a game where there are these boxes that you can spawn in, you are supposed to control it with your mouse. But some times they get very laggy. Please help.

01debounce = false
02player = game.Players.LocalPlayer
03b = Instance.new("BodyVelocity")
04b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
05b.Velocity = Vector3.new(0,0,0)
06mouse = player:GetMouse()
07house = script.Parent
08b.Parent = house
09moving = false
10function Talk(msg)
11    game:GetService("Chat"):Chat(house, player.Name..": "..msg, Enum.ChatColor.Red)
12end
13 
14function Aim()
15    if debounce == false then
View all 46 lines...

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
9 years ago

mouse.Hit is a CFrame. It looks like you're doing something convoluted to get the Position of a CFrame (Spawning a part at mouse.Hit and getting the Position of the part). Really, all you have to do it do mouse.Hit.p to get the Position of the CFrame.

This is what your Aim function would look like:

01function Aim()
02    if debounce == false then
03    debounce = true
04 
05    house.CFrame = CFrame.new(house.Position, mouse.Hit.p)
06 
07    if moving == true then
08        b.Velocity = Vector3.new(0,0,0)
09    b.Velocity = house.CFrame.lookVector*20
10    end
11    wait(.1)
12    debounce = false
13    end
14end

Honestly, this script probably isn't the biggest source of lag. There's something else going on in your game.

0
Thank you so much , I am ignorant of some of the syntax so that helped me alot QuantumToast 261 — 9y
Ad

Answer this question