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

how to make a clicking cool down when you click the sky ?

Asked by 4 years ago
Edited 4 years ago

A few hours ago i've made a pistol script (keep in mind that for the pistol script i used mouse.Target) but i met a error along the way in which i can't figure out a solution, so basically a pistol has a cool down, right ? it won't just shoot out bullets like a rifle so i made a cool down IF the mouse.Target is either terrain or a player, but what about the sky, the sky is equal to nil, how do i add a cool down if my mouse is pointing at the sky ? (debounce just messes up the script)

01local handle = script.Parent.Handle
02local tool = script.Parent
03local player = game.Players.LocalPlayer
04local gui = player:WaitForChild("PlayerGui")
05local screenGui = gui:WaitForChild("ScreenGui")
06local TextLabel = screenGui:WaitForChild("Ammo")
07local mouse = player:GetMouse()
08local mxAm = 10
09local Ammo1 = mxAm
10local serivce = game:GetService("UserInputService")
11local oldIcon = mouse.Icon
12 
13local function ammo2()
14    Ammo1 = mxAm
15end
View all 56 lines...

1 answer

Log in to vote
1
Answered by 4 years ago

Here's a script with the cooldown applied, I also rewrote it for you.

01if not game:IsLoaded() then
02    repeat
03        wait()
04    until game:IsLoaded()
05end
06 
07local Players = game:GetService("Players")
08local UserInputService = game:GetService("UserInputService")
09local RunService = game:GetService("RunService")
10 
11local LocalPlayer = Players.LocalPlayer
12local Character = LocalPlayer.Character
13local PlayerGui = LocalPlayer:FindFirstChildOfClass("PlayerGui")
14local Mouse = LocalPlayer:GetMouse()
15 
View all 89 lines...
0
thanks but i am getting errors saying: attempt to index nil with 'Text' and attempt to index nil with 'Visible' Random_Haxer5 10 — 4y
0
i respect what you did but the gun breaks when you shoot at the sky, it just stops working :/ Random_Haxer5 10 — 4y
Ad

Answer this question