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.
debounce = false
player = game.Players.LocalPlayer
b = Instance.new("BodyVelocity")
b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
b.Velocity = Vector3.new(0,0,0)
mouse = player:GetMouse()
house = script.Parent
b.Parent = house
moving = false
function Talk(msg)
game:GetService("Chat"):Chat(house, player.Name..": "..msg, Enum.ChatColor.Red)
end
function Aim()
if debounce == false then
debounce = true
local aimer = Instance.new("Part")
aimer.Transparency = 0
aimer.Anchored = true
aimer.CanCollide = false
aimer.Parent = game.Workspace
aimer.CFrame = mouse.Hit
house.CFrame = CFrame.new(house.Position, aimer.Position)
aimer:Destroy()
if moving == true then
b.Velocity = Vector3.new(0,0,0)
b.Velocity = house.CFrame.lookVector*20
end
wait(.1)
debounce = false
end
end
mouse.Move:connect(Aim)
mouse.Button1Down:connect(function()
moving = true
b.Velocity = house.CFrame.lookVector*20
mouse.Button1Up:connect(function()
moving = false
b.Velocity = Vector3.new(0,0,0)
end)
end)
player.Chatted:connect(Talk)

1 comment
Thank you so much , I am ignorant of some of the syntax so that helped me alot