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

Why won't these functions execute?

Asked by 6 years ago

I was making a script, but when I say to execute a function when a certain key is pressed, nothing happens. Also - don't say I should switch to RemoteEvents instead of KeyDown, because RemoteEvents are just awful... Here is the script:

wait(0.1)

local player = game.Players.LocalPlayer
local char = player.Character
local mouse = player:GetMouse()

local s1 = false
local s2 = false

ssj = false

function ssj()
    char.Torso.Anchored = true
    if ssj == false then ssj = true print("SSJ was false.") end
    delay(0, function()
        spawn(function()
            spawn(function()
                for i = 1, 25 do
                    local dust = Instance.new("Part", char.Torso)
                    dust.Anchored = true
                    dust.CanCollide = false
                    dust.Transparency = 0.5
                    dust.BrickColor = BrickColor.Yellow()
                    local dustmesh = Instance.new("SpecialMesh", dust)
                    dustmesh.MeshType = "FileMesh"
                    dustmesh.MeshId = "http://www.roblox.com/asset/?id=20329976"
                    dustmesh.Scale = Vector3.new(1,1,1)
                    dust.CFrame = char.Torso.CFrame - Vector3.new(0, 2.5, 0)
                    game.Debris:AddItem(dust, 1)
                    delay(0, function()
                        for i = 1, 20 do
                            dustmesh.Scale = dustmesh.Scale + Vector3.new(3.5, 1.75, 3.5)
                            dust.Transparency = dust.Transparency + 0.05
                            wait(0.1)
                        end
                    end)
                    wait(0.25)
                end
            end)
            s1 = true
        end)
        delay(0, function()
            for i = 1, 25 do
                local ball = Instance.new("Part", char.Torso)
                ball.Anchored = true
                ball.CanCollide = false
                ball.Transparency = 0
                ball.BrickColor = BrickColor.Yellow()
                ball.Shape = "Ball"
                ball.CFrame = char.Torso.CFrame
                ball.TopSurface = "Smooth"
                ball.BottomSurface = "Smooth"
                game.Debris:AddItem(ball, 1)
                delay(0, function()
                    for i = 1, 20 do
                        ball.Size = ball.Size + Vector3.new(2.5, 2.5, 2.5)
                        ball.Transparency = ball.Transparency + 0.05
                        wait(0.1)
                    end
                end)
                wait(0.25)
            end
        end)
        s2 = true
        delay(0, function()
            spawn(function()
                for i = 1, 5 do
                    local spike = Instance.new("Part", char.Torso)
                    spike.Anchored = true
                    spike.CanCollide = false
                    spike.Transparency = 0.5
                    spike.BrickColor = BrickColor.new("Deep orange")
                    spike.CFrame = char.Torso.CFrame
                    local m = Instance.new("SpecialMesh", spike)
                    m.MeshId = "rbxassetid://9982590"
                    game.Debris:AddItem(spike, 1)
                    delay(0,function()
                        for i = 1, 20 do
                            m.Scale = m.Scale + Vector3.new(2,2,2)
                            spike.Transparency = spike.Transparency + 0.05
                            spike.Orientation = spike.Orientation + Vector3.new(math.random(1, 10), math.random(1, 10), math.random(1, 10))
                            wait(0.1)
                        end
                    end)
                    wait(0.53)
                end
            end)
            delay(0,function()
                for i = 1, 12 do
                    local ring = Instance.new("Part", char.Torso)
                    ring.Anchored = true
                    ring.CanCollide = false
                    ring.Transparency = 0.5
                    ring.BrickColor = BrickColor.new("Deep orange")
                    ring.CFrame = char.Torso.CFrame
                    local m = Instance.new("SpecialMesh", ring)
                    m.MeshId = "http://www.roblox.com/asset/?id=3270017"
                    game.Debris:AddItem(ring, 1)
                    delay(0,function()
                        for i = 1, 20 do
                            m.Scale = m.Scale + Vector3.new(12,12,12)
                            ring.Transparency = ring.Transparency + 0.05
                            ring.Orientation = ring.Orientation + Vector3.new(math.random(-25, 25), math.random(-25, 25), math.random(-25, 25))
                            wait(0.25)
                        end
                    end)
                    wait(0.53)
                end
            end)
        end)
    end)
    wait(5)
    local acc = Instance.new("Accessory", char.Head)
    acc.Name = "SSJHair"
    local handle = Instance.new("Part", acc)
    handle.Name = "Handle"
    handle.CanCollide = false
    handle.BrickColor = BrickColor.new("Deep orange")
    handle.Material = "Neon"
    handle.Transparency = 1
    local m = Instance.new("SpecialMesh", handle)
    m.MeshId = "rbxassetid://430344159"
    m.Scale = Vector3.new(6, 6, 6)
    m.Offset = Vector3.new(0, 0.5, 0.5)
    local w = Instance.new("Weld", handle)
    w.Name = "AccessoryWeld"
    w.Part0 = handle
    w.Part1 = char.Head
    w.C0 = CFrame.new(0, -0.5, 0)
    char.Humanoid:AddAccessory(acc)
    for i = 1, 10 do
        handle.Transparency = handle.Transparency - 0.1
        wait(0.025)
    end
    for i, v in pairs(char:GetChildren()) do
        if v:IsA("Accessory") and v.Name ~= "SSJHair" then
            v.Handle.Transparency = 1
        end
    end
    local color1 = Color3.new(255, 255, 0)
    local p = game.ServerStorage.SSJAura:Clone()
    p.Parent = char.Torso
    p.Color = ColorSequence.new(color1)
    local l = Instance.new("ParticleEmitter", char.Torso)
    l.Size = NumberSequence.new({NumberSequenceKeypoint.new(0, 4, 0), NumberSequenceKeypoint.new(1, 4, 0)})
    l.Lifetime = NumberRange.new(0.1)
    l.Rate = 2
    l.Speed = NumberRange.new(2)
    l.VelocitySpread = NumberRange.new(400)
    l.Color = ColorSequence.new(Color3.new(171, 247, 255))
    l.LightEmission = 0.5
    l.Texture = "rbxassetid://281983189"
    local l2 = l:Clone()
    l2.Texture = "rbxassetid://278520320"
    local l3 = l:Clone()
    l3.Texture = "rbxassetid://281983280"
    local l4 = l:Clone()
    l4.Texture = "rbxassetid://281982895"
    local l5 = l:Clone()
    l5.Texture = "rbxassetid://281983242"
    l2.Parent = char.Torso
    l3.Parent = char.Torso
    l4.Parent = char.Torso
    l5.Parent = char.Torso
    s = Instance.new("Sound", char.Torso)
    s.Looped = true
    s.SoundId = "rbxassetid://828214895"
    s:Play()
    wait(4)
    s.TimePosition = 4
    spawn(function()
        while wait(116) and ssj == true do
            s.TimePosition = 4
        end
    end)
    char.Torso.Anchored = false
end

function nossj()
    s:Stop()
    for i, v in pairs(char:GetChildren()) do
        if v:IsA("Accessory") and v.Name ~= "SSJHair" then
            v.Handle.Transparency = 0
        end
    end
    char.SSJHair:Destroy()
    for i, v in pairs(char.Torso:GetChildren()) do
        if v:IsA("ParticleEmitter") then v:Destroy() end
    end
    if ssj == true then ssj = false print("SSJ was true.") end
end

mouse.KeyDown:connect(function(key)
    if string.lower(key) == "h" then
        wait(0.1)
        ssj()
    elseif string.lower(key) == "h" then
        wait(0.1)
        nossj()
    end
end)
0
Firstly, can you be more specific with where your error is, and where you called the function? A 201-line script is quite large, so could you please make it easier for us to solve? Also, although you aren't in favour of it, RemoteEvents are mandatory if you are using a LocalScript to create instances, due to FilteringEnabled. Furthermore, KeyDown is deprecated, so avoid using it. UgOsMiLy 1074 — 6y
0
I think I know where the problem is. "ssj" is the name of both a function and a variable, so it would confuse the script, and it doesn't know whether you are talking about the boolean or the function, so it assumes one, preferably the one that you don't want. Change "ssj" (the true/false value) to something else. UgOsMiLy 1074 — 6y
0
The problem is lines 194 & 197: Whenever the player hits the 'h' key, it'll always go to the first conditional statement; you'll have to set up your script to detect whether SSJ is on or off. TheeDeathCaster 2368 — 6y

Answer this question