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

can add wait time in between fire balls ?

Asked by 10 years ago

right now you can fire many fire balls at the same time and creates lag id like it to have a wait time in between each fire ball like 5 seconds

Player = script.Parent.Parent.Parent
mouse = Player:GetMouse()
local keydowns = script.Parent.Frame.keydown.Value
local keydown1 = script.Parent.skills.skill1.keydown.Value
local keydown2 = script.Parent.skills.skill2.keydown.Value
local keydown3 = script.Parent.skills.skill3.keydown.Value



mouse.KeyDown:connect(function (key) 
    key = key:lower()
if key == keydowns then
    script.Parent.Frame.Visible = not script.Parent.Frame.Visible
elseif key == keydown1 then
    local enabled = true
if not enabled then
        return
    end

    enabled = false
    local cf = mouse.Hit
    local target = cf.p
    fire(target)

    wait(1)
    enabled = true
elseif key == keydown2 then
    print "skill 2"
    elseif key == keydown3 then
    print "skill 3"
    end
end)




    function fire(target)
    local head = game.Players.LocalPlayer.Character:findFirstChild("Head")
    if head == nil then return end

    local dir = target - head.Position
    dir = computeDirection(dir)


    local missile = script.Parent.Rocket:clone()

    local spawnPos = game.Players.LocalPlayer.Character.PrimaryPart.Position

    local pos = spawnPos + (dir * 9)

    --missile.Position = pos
    missile.CFrame = CFrame.new(pos,  pos + dir)

    local creator_tag = Instance.new("ObjectValue")
    creator_tag.Value = game.Players.LocalPlayer
    creator_tag.Name = "creator"
    creator_tag.Parent = missile

    missile.RocketScript.Disabled = false

    missile.Parent = game.Workspace
end
function computeDirection(vec)
    local lenSquared = vec.magnitude * vec.magnitude
    local invSqrt = 1 / math.sqrt(lenSquared)
    return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

1 answer

Log in to vote
0
Answered by 10 years ago
Player = script.Parent.Parent.Parent
mouse = Player:GetMouse()
local debounce = false --The debounce which is false.
local keydowns = script.Parent.Frame.keydown.Value
local keydown1 = script.Parent.skills.skill1.keydown.Value
local keydown2 = script.Parent.skills.skill2.keydown.Value
local keydown3 = script.Parent.skills.skill3.keydown.Value



mouse.KeyDown:connect(function (key) 
    key = key:lower()
if key == keydowns then
    script.Parent.Frame.Visible = not script.Parent.Frame.Visible
elseif key == keydown1 then
    local enabled = true
if not enabled then
        return
    end

    enabled = false
    local cf = mouse.Hit
    local target = cf.p
    fire(target)

    wait(1)
    enabled = true
elseif key == keydown2 then
    print "skill 2"
    elseif key == keydown3 then
    print "skill 3"
    end
end)




    function fire(target)
if not debounce then --Checking if debounce is false
debounce = true --Change to true so this function can't activate anymore.
    local head = game.Players.LocalPlayer.Character:findFirstChild("Head")
    if head == nil then return end

    local dir = target - head.Position
    dir = computeDirection(dir)


    local missile = script.Parent.Rocket:clone()

    local spawnPos = game.Players.LocalPlayer.Character.PrimaryPart.Position

    local pos = spawnPos + (dir * 9)

    --missile.Position = pos
    missile.CFrame = CFrame.new(pos,  pos + dir)

    local creator_tag = Instance.new("ObjectValue")
    creator_tag.Value = game.Players.LocalPlayer
    creator_tag.Name = "creator"
    creator_tag.Parent = missile

    missile.RocketScript.Disabled = false

    missile.Parent = game.Workspace
wait(5)
debounce = false --Wait 5 seconds then let the function be abled to be called.
end
end
function computeDirection(vec)
    local lenSquared = vec.magnitude * vec.magnitude
    local invSqrt = 1 / math.sqrt(lenSquared)
    return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

Add a debounce. A debounce makes it so It doesn't spam everything. More on debouncing here.

Ad

Answer this question