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

How to make the player wait sometime before this is used again?

Asked by 9 years ago
player = script.Parent.Parent.Parent
me = script.Parent.Parent.Parent

enabled = true

function Talk(msg)
game:GetService("Chat"):Chat(player.Character.Head, msg, Enum.ChatColor.Blue)
end

me = script.Parent.Parent.Parent
player = script.Parent.Parent.Parent
function onKeyDown(key) 
key:lower() 
if key == "z" then 
    local player = game.Players.LocalPlayer
    if player == nil then return end

    oldws = me.Character.Humanoid.WalkSpeed
    enabled = false 
    RightShoulder = me.Character.Torso["Right Shoulder"]
        LeftShoulder = me.Character.Torso["Left Shoulder"]
        Run = game:GetService("RunService")
            for i = 1, 3 do
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 1)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -1)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 1.1, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, -1.1, 0)
                Run.Stepped:wait(0.005)
            end
        me.Character.Torso.Anchored = false
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Bright red")
        k.Size = Vector3.new(1, .1, 1)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 1
        f = Instance.new("Sparkles", k)
        f.Color = Color3.new(255, 255, 255)
        k.Parent = me.Character
        v = Instance.new("Decal")
        v.Texture = "http://www.roblox.com/asset/?id=214848407"
        v.Face = "Top"
        v.Parent = k
        p = Instance.new("PointLight", k)
        p.Brightness = 10
        p.Range = 20
        p.Color = Color3.new(255, 255, 255)
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Brick"
        z.Scale = Vector3.new(3, 0, 3)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(0, -3, 0)
        game.Debris:AddItem(k, 9)
        wait(0.15)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(3, 0, 2.5)
                wait(0.10)
            end
        Talk("With a flame in my right hand...")
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Bright red")
        k.Size = Vector3.new(3, 3, 3)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 0.5
        k.Parent = Workspace
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Sphere"
        z.Scale = Vector3.new(0.2, 0.2, 0.2)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(2.5, 0, 0)
        game.Debris:AddItem(k, 2)
        wait(0.05)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(.1, .1, .1)
                wait(0.05)
            end
        Talk("And a flame in my left hand...")
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Deep orange")
        k.Size = Vector3.new(3, 3, 3)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 0.5
        k.Parent = Workspace
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Sphere"
        z.Scale = Vector3.new(0.2, 0.2, 0.2)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(-2.5, 0, 0)
        game.Debris:AddItem(k, 2)
        wait(0.05)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(.1,.1,.1)
                wait(0.05)
            end
            for i = 1, 3 do
            LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 1.1, 0)
            RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, -1.1, 0)
            LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, -1)
            RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 1)
            Run.Stepped:wait(0.01)
            end
            for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0.27)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, -0.27)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0.004)
            end
        Talk("Combine the flames together...")
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Really red")
        k.Size = Vector3.new(2, 2, 2)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 0.5
        k.Parent = Workspace
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Sphere"
        z.Scale = Vector3.new(0.2, 0.2, 0.2)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(0, 10, 0)
        game.Debris:AddItem(k, 2)
        wait(0.7)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(1,1,1)
                wait(0.05)
            end
                for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -0.27)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0.27)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0.004)
                end
                for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0.12)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, -0.12)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0.004)
            end
            Talk("Fire Dragon's Brilliant Flame!")
        for i = 1, 1 do
        x = Instance.new("Part")
        x.BrickColor = BrickColor.new("Really red")
        x.Size = Vector3.new(20, 20, 20)
        x.TopSurface = "Smooth"
        x.BottomSurface = "Smooth"
        x.Shape = "Ball"
        x.Name = me.Name
        x.CanCollide = false
        x.Transparency = 0.5

        p = Instance.new("PointLight", x)
        p.Brightness = 10
        p.Range = 15
        p.Color = Color3.new(255, 0, 0)
        fd = script.Firedamage:clone()
        fd.Parent = x
        y = Instance.new("BodyVelocity")
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = me.Character.Torso.CFrame.lookVector*50
        x.Parent = Workspace
        y.Parent = x
        x.CFrame = me.Character.Torso.CFrame*CFrame.new(0, 3, -15)
        fd.Disabled = false
        game.Debris:AddItem(x, 6)
        wait()
        end

        me.Character.Humanoid.WalkSpeed = oldws



me.Character.Torso.Anchored = false
        for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -0.12)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0.12)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0)
            end
    wait(20)
enabled = true
    end


enabled = true
end

function onSelected(mouse) 
mouse.KeyDown:connect(onKeyDown) 
end 

script.Parent.Selected:connect(onSelected)

Because this will allow the player to use this over and over.

1 answer

Log in to vote
0
Answered by 9 years ago

Use something called a Debounce. It makes sure the player only does it once then has to wait. For example: If you have a part with a Touched script in it that says:

Workspace.Button.Touched:connect(function(hit)
    print("Button pressed")
    wait(1)
    print("Hi :D")
end)

the output would say

Button pressed Button pressed Button pressed Button pressed Button pressed Hi :D Hi :D Hi :D Hi :D Hi :D

So we need to add a debounce.

local debounce = false --could be false or true. Just need to adjust the script if you need too.

then we use an If statement. We could also say not if the debounce is false. If it's true then don't add the not,

this is the script from before with the debounce:

local debounce = false

Workspace.Button.Touched:connect(function(hit)
    if not debounce then
        debounce = true
        wait(1)
        print("Hi :D")
        debounce = false
    end
end)

The output would be:

Button pressed Hi :D


Now we add this with your script:

local debounce = false --Debounce
player = script.Parent.Parent.Parent
me = script.Parent.Parent.Parent

enabled = true

function Talk(msg)
game:GetService("Chat"):Chat(player.Character.Head, msg, Enum.ChatColor.Blue)
end

me = script.Parent.Parent.Parent
player = script.Parent.Parent.Parent
function onKeyDown(key) 
if key:lower() == "z" then
if not debounce then --If the debounce is false then...
debounce = true --Don't spam
    local player = game.Players.LocalPlayer
    if player == nil then return end

    oldws = me.Character.Humanoid.WalkSpeed
    enabled = false 
    RightShoulder = me.Character.Torso["Right Shoulder"]
        LeftShoulder = me.Character.Torso["Left Shoulder"]
        Run = game:GetService("RunService")
            for i = 1, 3 do
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 1)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -1)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 1.1, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, -1.1, 0)
                Run.Stepped:wait(0.005)
            end
        me.Character.Torso.Anchored = false
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Bright red")
        k.Size = Vector3.new(1, .1, 1)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 1
        f = Instance.new("Sparkles", k)
        f.Color = Color3.new(255, 255, 255)
        k.Parent = me.Character
        v = Instance.new("Decal")
        v.Texture = "http://www.roblox.com/asset/?id=214848407"
        v.Face = "Top"
        v.Parent = k
        p = Instance.new("PointLight", k)
        p.Brightness = 10
        p.Range = 20
        p.Color = Color3.new(255, 255, 255)
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Brick"
        z.Scale = Vector3.new(3, 0, 3)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(0, -3, 0)
        game.Debris:AddItem(k, 9)
        wait(0.15)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(3, 0, 2.5)
                wait(0.10)
            end
        Talk("With a flame in my right hand...")
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Bright red")
        k.Size = Vector3.new(3, 3, 3)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 0.5
        k.Parent = Workspace
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Sphere"
        z.Scale = Vector3.new(0.2, 0.2, 0.2)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(2.5, 0, 0)
        game.Debris:AddItem(k, 2)
        wait(0.05)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(.1, .1, .1)
                wait(0.05)
            end
        Talk("And a flame in my left hand...")
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Deep orange")
        k.Size = Vector3.new(3, 3, 3)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 0.5
        k.Parent = Workspace
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Sphere"
        z.Scale = Vector3.new(0.2, 0.2, 0.2)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(-2.5, 0, 0)
        game.Debris:AddItem(k, 2)
        wait(0.05)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(.1,.1,.1)
                wait(0.05)
            end
            for i = 1, 3 do
            LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 1.1, 0)
            RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, -1.1, 0)
            LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, -1)
            RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 1)
            Run.Stepped:wait(0.01)
            end
            for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0.27)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, -0.27)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0.004)
            end
        Talk("Combine the flames together...")
        k = Instance.new("Part")
        k.BrickColor = BrickColor.new("Really red")
        k.Size = Vector3.new(2, 2, 2)
        k.TopSurface = "Smooth"
        k.BottomSurface = "Smooth"
        k.Shape = "Ball"
        k.Name = me.Name
        k.CanCollide = false
        k.Anchored = true
        k.Transparency = 0.5
        k.Parent = Workspace
        z = Instance.new("SpecialMesh", k)
        z.MeshType = "Sphere"
        z.Scale = Vector3.new(0.2, 0.2, 0.2)
        me.Character.Humanoid.WalkSpeed = 0
        k.CFrame = me.Character.Torso.CFrame*CFrame.new(0, 10, 0)
        game.Debris:AddItem(k, 2)
        wait(0.7)
            for i = 1,7 do
                z.Scale = z.Scale +Vector3.new(1,1,1)
                wait(0.05)
            end
                for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -0.27)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0.27)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0.004)
                end
                for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0.12)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, -0.12)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0.004)
            end
            Talk("Fire Dragon's Brilliant Flame!")
        for i = 1, 1 do
        x = Instance.new("Part")
        x.BrickColor = BrickColor.new("Really red")
        x.Size = Vector3.new(20, 20, 20)
        x.TopSurface = "Smooth"
        x.BottomSurface = "Smooth"
        x.Shape = "Ball"
        x.Name = me.Name
        x.CanCollide = false
        x.Transparency = 0.5

        p = Instance.new("PointLight", x)
        p.Brightness = 10
        p.Range = 15
        p.Color = Color3.new(255, 0, 0)
        fd = script.Firedamage:clone()
        fd.Parent = x
        y = Instance.new("BodyVelocity")
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = me.Character.Torso.CFrame.lookVector*50
        x.Parent = Workspace
        y.Parent = x
        x.CFrame = me.Character.Torso.CFrame*CFrame.new(0, 3, -15)
        fd.Disabled = false
        game.Debris:AddItem(x, 6)
        wait()
        end

        me.Character.Humanoid.WalkSpeed = oldws



me.Character.Torso.Anchored = false
        for i = 1, 12 do
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -0.12)
                RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0.12)
                LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0)
                Run.Stepped:wait(0)
            end
    wait(20)
enabled = true
debounce = true
    end


enabled = true
end

function onSelected(mouse) 
mouse.KeyDown:connect(onKeyDown) 
end 

script.Parent.Selected:connect(onSelected)
Ad

Answer this question