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

How can I get the mouse's position from the server without spamming remotefunctions?

Asked by 6 years ago

I'm trying to make the character move towards their mouse position, but it lags. I figured out the reason for this lag is because I'm calling the MousePos remotefunction way too much. Is there a way that I can get the player's mouse position every time the loop repeats, without causing lag?

___________________________________________________________________________

Here is the loop:

function activateBroom(player, count, maxcount, mouse)
    repeat
        wait()
        local mousepos = remotes.Parent.ServerToClient.MousePos:InvokeClient(player)
        player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.CFrame.p, mousepos.p) * CFrame.new(0, 0, -1)
        count = count + 1
    until count == maxcount
end

remotes.LearnedMoves.OnServerEvent:connect(activateBroom)
-- didnt bother to rename the remote event yet, i was using it for a different purpose before.

Here is the localscript that handles the remotes:

local remotes = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ServerToClient")

function returnMousePos()
    return game.Players.LocalPlayer:GetMouse().Hit
end

remotes.MousePos.OnClientInvoke = returnMousePos
0
Use the .Enabled argument of the tool. hiimgoodpack 2009 — 6y
0
what the heck are you talking about? there's no tool involved in this lmao Operation_Meme 890 — 6y
0
I'm not really sure what to do either, I asked the same question, but maybe try making a value for a certain player in repstore and making the client set the value to the position. Also if you're trying to make it a bit faster use RunService.RenderStepped:Wait(). Corexty 15 — 6y
0
maybe update it 30 or 20 times a second instead of 60 abnotaddable 920 — 6y
View all comments (3 more)
0
I tried RunService.RenderStepped but it only made it a bit smoother. i think it's because roblox limits the fps to 60? Operation_Meme 890 — 6y
0
It's a broom. Why wouldn't it be a tool? hiimgoodpack 2009 — 6y
0
maybe i don't want it to be a tool... maybe it's a magical flying broom lmao Operation_Meme 890 — 6y

Answer this question