Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make my fireball launch when a person clicks(Computer) or taps(Mobile)?

So I have made a fireball that launches once u press E, but obviously not everyone can activate it.. So how do I make it so when someone clicks it launches and when someone taps if they are on mobile launches it? Also, if my code is bad, maybe its because I started coding 5 days ago.. Sorry. TY!

Code:

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
local ammo = 1

local x = Instance.new("Part")
	x.BrickColor = BrickColor.new("Maroon")
	x.Shape = "Ball"
	x.Material = "Neon"
	x.TopSurface = "Smooth"
	x.BottomSurface = "Smooth"
	x.Anchored = false
	x.CanCollide = true
    x.Transparency = 0.5
	x.Size = Vector3.new(3,3,3);

local y = Instance.new("Fire")
	y.Size = 15
	y.Heat = 5





game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
	
	local animation = Instance.new("Animation")
				animation.AnimationId = "http://www.roblox.com/asset/?id=855830361"
	local humanoid = script.Parent:WaitForChild('Humanoid')
          		humanoid:LoadAnimation(animation):Play()
  wait(1.5)

if ammo == 1 then
        local cl = x:Clone()  
		local cly = y:Clone()
		local v = Instance.new("BodyVelocity")
				v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
				v.Velocity = Player.Character.UpperTorso.CFrame.lookVector * 60
				v.Parent = cl
				cly.Parent = cl
        		cl.Parent = game.Workspace 
       			cl.CFrame = Player.Character.UpperTorso.CFrame * CFrame.new(0,1,-5)
				ammo = 0
				game.Debris:AddItem(cl, 4)
				wait(2)
				ammo = 1
		end 					 										
    end
end)


1 comment

1 answer

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
local ammo = 1
local Mouse = Player:GetMouse()  -- NEW VARIABLE

local x = Instance.new("Part")
    x.BrickColor = BrickColor.new("Maroon")
    x.Shape = "Ball"
    x.Material = "Neon"
    x.TopSurface = "Smooth"
    x.BottomSurface = "Smooth"
    x.Anchored = false
    x.CanCollide = true
    x.Transparency = 0.5
    x.Size = Vector3.new(3,3,3);

local y = Instance.new("Fire")
    y.Size = 15
    y.Heat = 5




Mouse.Button1Down:connect(function() --DETECTS CLICK/TAP

 local animation = Instance.new("Animation")
                animation.AnimationId = "http://www.roblox.com/asset/?id=855830361"
    local humanoid = script.Parent:WaitForChild('Humanoid')
                humanoid:LoadAnimation(animation):Play()
  wait(1.5)

if ammo == 1 then
        local cl = x:Clone()  
        local cly = y:Clone()
        local v = Instance.new("BodyVelocity")
                v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
                v.Velocity = Player.Character.UpperTorso.CFrame.lookVector * 60
                v.Parent = cl
                cly.Parent = cl
                cl.Parent = game.Workspace 
                cl.CFrame = Player.Character.UpperTorso.CFrame * CFrame.new(0,1,-5)
                ammo = 0
                game.Debris:AddItem(cl, 4)
                wait(2)
                ammo = 1
        end                          
	
end)




-- THIS IS FOR CLICKING E

game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then

    local animation = Instance.new("Animation")
                animation.AnimationId = "http://www.roblox.com/asset/?id=855830361"
    local humanoid = script.Parent:WaitForChild('Humanoid')
                humanoid:LoadAnimation(animation):Play()
  wait(1.5)

if ammo == 1 then
        local cl = x:Clone()  
        local cly = y:Clone()
        local v = Instance.new("BodyVelocity")
                v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
                v.Velocity = Player.Character.UpperTorso.CFrame.lookVector * 60
                v.Parent = cl
                cly.Parent = cl
                cl.Parent = game.Workspace 
                cl.CFrame = Player.Character.UpperTorso.CFrame * CFrame.new(0,1,-5)
                ammo = 0
                game.Debris:AddItem(cl, 4)
                wait(2)
                ammo = 1
        end                                                             
    end
end)


This discussion is preserved as it was. New answers, comments, and votes are closed.