I’m trying to make a 3d drawing system (it’s kinda 3d, along only the x/y axes) using parts and have them go to the mouse cursor. That already works, and it goes to the mouse cursor, but if you move your mouse super fast it kinda lags behind. I’m just trying to fix this, and I’ve tried a few things but can’t really get it to work.
-- Local Script (parented to PlayerScripts)
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local uis = game:GetService("UserInputService")
local mouseHeld = false
local cam = workspace.CurrentCamera
mouse.Button1Down:Connect(function()
mouseHeld = true
end)
mouse.Button1Up:Connect(function()
mouseHeld = false
end)
while true do
if mouseHeld then
game:GetService("ReplicatedStorage"):WaitForChild("remotes"):WaitForChild("buildPart"):FireServer(mouse.Hit)
end
wait()
end
-- Server Script (parented to ServerScriptService)
local remote = game:GetService("ReplicatedStorage"):WaitForChild("remotes"):WaitForChild("buildPart")
remote.OnServerEvent:Connect(function(plr, pos)
local part = Instance.new("Part")
part.Shape = Enum.PartType.Cylinder
part.Anchored = true
part.Size = Vector3.new(7, 1, 1)
part.Parent = game.Workspace
local newPos = CFrame.new(pos.X, pos.Y, -4.951)
part.CFrame = newPos
part.Orientation = Vector3.new(0, 90, 0)
end)
All I’m going to say is change that wait() to task.wait() and define the remote event and replicated storage before firing the event…
Haven’t really worked with mouse stuff so this is like the best I can offer
You can always use a unreliable remote event for faster results but sometimes events won’t always go through. Another way to make it be more responsive is create parts on the client as a visual and have the server verify and create the actual part. If client misplaced a part server can just tell them to delete it.
Sorry if this isn’t very helpful, but that script seems laggy/inneficient on its own,
spamming a while true do on an if state is bound to lag, and then might not spawn the cyclinders as fast as possible, i’m not very good at scripting, but you might want to use RunService.Heartbeat to spawn a cylinder every frame to look smooth.
I’m not sure how I’d exactly go about this, in the case that there’s a wide gap between the last mouse position and the current one due to fast movements, you could try and make it so it puts the parts in position increments in a for loop until it reaches the current mouse position as if you were filling in a space rather than just putting it at the mouse position so that it would compensate for the gap in between the last and current mouse positions