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

How do you make it so if you hold down the button, a blast gets larger and does more damage??

Asked by 6 years ago

Basically, I made a fireball that shoots when I press the letter f. But I want to make it so if I hold down f, the fireball will get larger and then I can release to fire it off. How do I do this?

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Hi Tim,

What you're trying to accomplish is simple and the answer previous to this by chexy doesn't answer your question.You want the blast to keep growing when you keep holding down the key, and you need to use booleans for that. You make a boolean true upon clicking, and make it false upon ending the click. And while the boolean is true, you need to run a function that increases the size. Here, I'll just show you how to do it using UserInputService.

local uis = game:GetService("UserInputService");
local players = game:GetService("Players");
local player = players.LocalPlayer;
local holding_down = false;

uis.InputBegan:Connect(function(obj, gp)
    if obj.KeyCode == Enum.KeyCode.Q and not gp then
        holding_down = true;
        local part; -- Define the part somehow and I'm going to assume this part's had it's appropriate properties set.

        while holding_down and wait() do
            part.Size = part.Size + Vector3.new(.1, .1, .1); -- Adds this to the size while the key is being held.
        end
    end
end)

uis.InputEnded:Connect(function(obj, gp)
    if obj.KeyCode == Enum.KeyCode.Q and not gp then
        holding_down = false;
    end
end)

Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
how did you make text so big? BlackOrange3343 2676 — 6y
0
I had an issue, you put " local players = players:GetService("Players"); " But it's an error, it says " attempt to index global 'players' (a nil value)" You can't use players when your defining players I think Timbawolf1 6 — 6y
0
Lol, let me update. KingLoneCat 2642 — 6y
0
There, it should work now. KingLoneCat 2642 — 6y
View all comments (11 more)
0
Black, you use '#' Doing ## at the beginning of the line makes it big. # is the biggest, ## is the next biggest, ### is the next biggest, and #### is an italicized different font style text. Test them out. KingLoneCat 2642 — 6y
0
The script doesn't work. Timbawolf1 6 — 6y
0
Make sure it's a local script on the client. KingLoneCat 2642 — 6y
0
It is a local script. Timbawolf1 6 — 6y
0
Did you define the part and set the part's properties? KingLoneCat 2642 — 6y
0
Yes I did. Timbawolf1 6 — 6y
0
This is what I put to define it: local part = Instance.new("Part"); part.Size = Vector3.new(5,5,5) part.BrickColor = BrickColor.new(255,0,0) part.CFrame = player.Character.UpperTorso.CFrame part.CanCollide = true Timbawolf1 6 — 6y
0
Did you parent the part to workspace? KingLoneCat 2642 — 6y
0
Also, BrickColor isn't a BrickColor3 value. So, you don't use 3 values. Just look up the names for each color and you put that in BrickColor.new(). KingLoneCat 2642 — 6y
0
:D It works now, thanks! I hope I didn't disturb you. Timbawolf1 6 — 6y
0
No, it's fine. Lol. KingLoneCat 2642 — 6y
Ad
Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

You can use UserInputService or ContextActionService for keybinding. Here's to start you off; This is a LocalScript:

local uis = game:GetService('UserInputService')

uis.InputBegan:Connect(function(key, gpe)
        -- When a key is pressed, this event is fired
        if key.KeyCode == Enum.KeyCode.F then --A check to see if the player pressed the 'F' key
               -- increase dmg and size of fireball
        end
end)

uis.InputEnded:Connect(function(key, gpe) then
       -- If a player has let go of a key, this event is fired.
       if key.KeyCode == Enum.KeyCode.F then --A check to see if the 'F' key was let go of
              -- Release the fireball and deal some damage to the player it hit, if it has
       end
end

Answer this question