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

How to make a script to detect a gun firing (for GUI)?

Asked by 4 years ago

Hello so me and 2 of my friends are making a shooter game we have animations and multiple guns and ray casting for the bullets

I have been assigned to making a ammo counter GUI and reload script the problem is i have never made one before and need it made by the end of today. below is my friends script

001local RayModule = require(game:GetService("ReplicatedStorage").ModuleScripts:WaitForChild("RayModule") )
002local HurtEvent = game:GetService("ReplicatedStorage"):WaitForChild("HurtHumanoid")
003local RunService = game:GetService('RunService')
004local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
005local UserInputService = game:GetService("UserInputService")
006 
007 
008local tool = script.Parent
009local CoolDown = false
010 
011 
012local function createPreviewAnimation(keyframeSequence)
013        local hashId = KeyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
014        if hashId then
015            local Animation = Instance.new("Animation")
View all 100 lines...

Now i have tried a couple of things 1 of which was to use function ToolActivated() and it does not seem to work I have it set up so that i can do ammo - 1 every time the gun is fired i just need to find a way to detect that below is my code for that

1local UserInputService = game:GetService("UserInputService")
2local status = game.ReplicatedStorage:WaitForChild("Status")
3local tool = game.StarterPack.DevGun
4local Ammo = 15
5 
6    status.Value = Ammo - 1

any help is much appreciated thanks -proplayer700

0
Everytime you shoot, use an if condition to check if it is zero or less than that. Reload if it is. radiant_Light203 1166 — 4y

Answer this question