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

How would I fix my gun script?

Asked by 9 years ago

I want to try making the gun script, automatic. But the problem is I don't know how to trigger it properly. Look down for examples.

Here's an brief-example of what I did so far:

mouse.Button1Down:connect(function()
    mouse.Button1Up:connect(function()
        game.ReplicatedStorage.ROBLOX_MP5FireEvent:FireServer(mouse.Hit.p)
    end)

Then here's my next one, it works fine but it shoots not automatic but pistol type. Where you have to spam click.

mouse.Button1Down:connect(function()
        game.ReplicatedStorage.ROBLOX_MP5FireEvent:FireServer(mouse.Hit.p)
    end)

3 answers

Log in to vote
1
Answered by 9 years ago

Then what's the real fix to this?

1
renderstepped still works fine but if you want use while wait() do Hero_ic 502 — 9y
0
Where do I put the while wait() at? ShinoKae 0 — 9y
0
and also, it didnt work. ShinoKae 0 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Try to do with some variables. Like,

--This must be a LocalScript
local FireRate = 0.1
local on = false
local PL = game.Players.LocalPlayer
local MS = PL:GetMouse()
local MSPos = MS.Hit.p
local SEvent = game.ReaplicatedStorage.ROBLOX_MP5FireEvent
function Enable()
    on = true
end

function Disable()
    on = false
end

while on == true do
    wait(FireRate)
    SEvent:FireServer(MSPos)
end

PM me on ROBLOX and say me if it works (Loulou1112)

0
Variables don't help more - in fact, in most cases it's better to refer directly to your goal than use variable over variable which variables you are probably only going to use 2 or 3 of them which other variables you used to create the variables you'll actually use. In other words, this doesn't solve anything. Marios2 360 — 9y
Log in to vote
0
Answered by
Hero_ic 502 Moderation Voter
9 years ago

What you can do is make a variable and use renderstepped.

local fire = false

game:GetService.RunSerivce:RenderStepped:connect(function()
    if fire == true then
      game.ReplicatedStorage.ROBLOX_MP5FireEvent:FireServer(mouse.Hit.p)
    end
end)

mouse.Button1Down:connect(function()
       fire = true
    end)
mouse.Button1Up:connect(function()
        fire = false
    end)

if this helped please accept :) ~KIHeros

Oh and if you want a firerate you can add a firerate variable

local fireRate = 0.2

--then make it wait the fireRate

if fire == true then
  wait(fireRate)
  game.ReplicatedStorage.ROBLOX_MP5FireEvent:FireServer(mouse.Hit.p)
end

1
game:GetService.RunSerivce.RenderStepped:connect()* Also, RenderStepped fires every time the client renders, and if the server keeps recieving events via the network on every client's render it can get laggy. Marios2 360 — 9y

Answer this question