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

How do I put a function in a function?

Asked by 8 years ago

OK so look, this is a fireball function:

wait(1)

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local humanoid = player.Character.Humanoid 
local s = humanoid:LoadAnimation(game.StarterPack.StarterPack.Animation)

Player = script.Parent.Parent  
Character = Player.Character 
Mouse = Player:GetMouse()  
usable = true

function onKeyDown(key) 
    key = key:lower() 
    if key == "f" and usable then 
    usable = false 
        s:Play()
        player.Character.Humanoid.WalkSpeed = 16
        wait(.73)
        local x = Instance.new("Part")
        x.TopSurface = "Smooth" 
        x.BottomSurface = "Smooth" 
        x.Shape = "Ball" 
        x.Transparency = .7
        x.BrickColor = BrickColor.new("Bright red")
        x.Size = Vector3.new(10, 10, 10)
        local z = Instance.new("Fire") 
        z.Parent = x 
        z.Size = 12 
        z.Heat = 12
        local explosion = Instance.new("Explosion")
        explosion.Parent = game.Workspace
        explosion.Position = x.Position
        local y = Instance.new("BodyVelocity") 
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = Character.Torso.CFrame.lookVector*80
        y.Parent = x  
        x.Parent = game.Workspace 
        x.CFrame = Character.Torso.CFrame*CFrame.new(0, 0, -12)
        wait(3.5)
        x:remove()
    wait(.6) 
    usable = true 
        end
    end

Mouse.KeyDown:connect(onKeyDown)

I wanna add a OnTouched function so when this fireball touches a humanoid, it disappears and does damage to the humanoid. But idk how to put a function -- into a function. .-.

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

Well, you defined the part that the fireball is, so, just insert in an anonymous function for when it's touched:

wait(1)

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local humanoid = player.Character.Humanoid 
local s = humanoid:LoadAnimation(game.StarterPack.StarterPack.Animation)

Player = script.Parent.Parent  
Character = Player.Character 
Mouse = Player:GetMouse()  
usable = true

function onKeyDown(key) 
    key = key:lower() 
    if key == "f" and usable then 
    usable = false 
        s:Play()
        player.Character.Humanoid.WalkSpeed = 16
        wait(.73)
        local x = Instance.new("Part")
        x.TopSurface = "Smooth" 
        x.BottomSurface = "Smooth" 
        x.Shape = "Ball" 
        x.Transparency = .7
        x.BrickColor = BrickColor.new("Bright red")
        x.Size = Vector3.new(10, 10, 10)
        local z = Instance.new("Fire") 
        z.Parent = x 
        z.Size = 12 
        z.Heat = 12
        local explosion = Instance.new("Explosion")
        explosion.Parent = game.Workspace
        explosion.Position = x.Position
        local y = Instance.new("BodyVelocity") 
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = Character.Torso.CFrame.lookVector*80
        y.Parent = x  
        x.Parent = game.Workspace 
        x.CFrame = Character.Torso.CFrame*CFrame.new(0, 0, -12)

        x.Touched:connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") then
                hit.Parent.Humanoid:TakeDamage(10) -- Replace with damage amount.
                if x then -- Just in case, to counter the event that the fireball gets deleted before this.
                    x:Destroy()
                end
            end
        end)

        wait(3.5)
        x:remove()
    wait(.6) 
    usable = true 
        end
    end

Mouse.KeyDown:connect(onKeyDown)

0
Also, did you check out those links I took the time to add in to your other question..? Pyrondon 2089 — 8y
0
Oh! I forgot to check them! I'll check them now. Thx man. james24dj 90 — 8y
0
No problem. Pyrondon 2089 — 8y
Ad

Answer this question