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

Minimizing Filtering Enabled Gun Lag?

Asked by
Eqicness 255 Moderation Voter
7 years ago
Edited 7 years ago

Hi, so I've created a gun script over the past few days and it works perfectly fine except for the fact that:

I can't use mouse.Hit from the Script, although I got the mouse from the tool.Equipped event. It's giving me an error that "The Mouse is no longer active." I've done some research and the ROBLOX Staff are looking into it, and they're looking to depreciate the mouse object soon.

As a substitute, I'm using a Remote Function to get the player's mouse.Hit from a local script, although this slows down my fire function by ~0.1 seconds.

In short, my question is there any way to minimize lag and get the place the mouse is pointing to without using mouse.Hit? I know there's always ray casting, I can look into that.

0
is this a bug report, or is it a question? Lol Nikkulaos 229 — 7y
0
Edited so it's better stated @Nikkulai. Eqicness 255 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Here's how I made my gun:

I used tool.Equipped and tool.Unequipped to change a "equipped" bool

I used a MouseButton1Down in a LocalScript to activate everything and check if the tool was equipped

I then checked if they had enough ammo and to check if it's less than or equal to the amount of max bullets

--// For firing (your question)

Use a repeat loop and define the mouse's position inside of it.

Ex.

local plr = game.Players.LocalPlayer local mouse = plr:GetMouse()

repeat local mousePos = mouse.Hit.p remote:FireServer(mousePos) wait(0.1) until the player has ran out of ammo or something

On the ServerSide of the gun and inside of the RayCasting script, just add the variable in the first value and it should be good.

This is what my Ray creation looks like

ray = Ray.new(tool.Handle.CFrame.p, (hit - tool.Handle.CFrame.p).unit * module.Settings.Range) end

0
Thank you for the answer, but I've already coded the gun and it works fine. I'm wondering how I can minimize lag because using a RemoteEvent to shoot lazers is pretty laggy. Eqicness 255 — 7y
0
I'm not sure if you'll see this or if it'd help but I found a new method. Basically when you create the bullet on the client, then you fire a RemoteEvent with all the properties of the created bullet. Then make the RemoteEvent fire another event that replicates the bullets to everyone. It's hard to explain so if you need a better understand add me. Discord - Goat#2976 gmatchOnRoblox 103 — 7y
Ad
Log in to vote
0
Answered by
Eqicness 255 Moderation Voter
5 years ago

To anybody reading the question in the future,

Since posting this I've learned a lot about scripting projectiles, and a comment that gmatchOnRoblox wrote on the previous answer gives a lot of insight that I wish I would've seen a year ago. This is the method I now use, and it's the best I can think of. I believe it's used in most projectile scripting on Roblox, and in the game industry, today. Here's what gmatchOnRoblox wrote in the comment on the previous answer:

I'm not sure if you'll see this or if it'd help but I found a new method. Basically when you create the bullet on the client, then you fire a RemoteEvent with all the properties of the created bullet. Then make the RemoteEvent fire another event that replicates the bullets to everyone. It's hard to explain so if you need a better understand add me.

Hope this helps future scripters reading this, and good luck with your projects!

Answer this question