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

I need help editing a script to make it more efficient and better, easy to read [?]

Asked by 6 years ago

here's my code;

local teamForFirstGuy
local BlueSpawn = game.Workspace:WaitForChild('BlueTower').BlueSpawn
local RedSpawn = game.Workspace:WaitForChild('RedTower').RedSpawn
local AOP = game.ServerStorage:WaitForChild('AmountOfPlayers')
local BlueEffect = game.Lighting:WaitForChild('Blur')
local W = 0.07

game.Players.PlayerAdded:connect(function(plr)
    wait(W)
    AOP.Value = AOP.Value + 1

    local Stats = Instance.new('Model')
    Stats.Name = 'PlrStats'
    Stats.Parent = plr


    local Team = Instance.new("StringValue")
    Team.Name = "Team"

    if teamForFirstGuy then
        Team.Value = teamForFirstGuy == "Blue" and "Red" or "Blue"
    else
        Team.Value = math.random() < .5 and "Blue" or "Red"
        teamForFirstGuy = Team.Value

        Team.Parent = Stats

        plr.CharacterAdded:Connect(function(char)
            if Team.Value == 'Red' then
                wait()
                char:WaitForChild('HumanoidRootPart').CFrame = BlueSpawn.CFrame
            else
                wait()
                char:WaitForChild('HumanoidRootPart').CFrame = RedSpawn.CFrame
            end
        end)    
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    local IntroText = plr.PlayerGui:WaitForChild('MainGui').LoadingLabel
    local BattleFrame = plr.PlayerGui:WaitForChild('MainGui').BattleFrame

    if AOP.Value == 1 then
        BlueEffect.Size = 24
        IntroText.Visible = true
        while true do
            wait(2)
            IntroText.Text = 'Need One More Player!'
            wait(W)
            IntroText.TextStrokeTransparency = 0.1
            IntroText.TextTransparency = 0.1
            wait(W)
            IntroText.TextStrokeTransparency = 0.2
            IntroText.TextTransparency = 0.2
            wait(W)
            IntroText.TextStrokeTransparency = 0.3
            IntroText.TextTransparency = 0.3
            wait(W)
            IntroText.TextStrokeTransparency = 0.4
            IntroText.TextTransparency = 0.4
            wait(W)
            IntroText.TextStrokeTransparency = 0.5
            IntroText.TextTransparency = 0.5
            wait(W)
            IntroText.TextStrokeTransparency = 0.6
            IntroText.TextTransparency = 0.6
            wait(W)
            IntroText.TextStrokeTransparency = 0.7
            IntroText.TextTransparency = 0.7
            wait(W)
            IntroText.TextStrokeTransparency = 0.8
            IntroText.TextTransparency = 0.8
            wait(W)
            IntroText.TextStrokeTransparency = 0.9
            IntroText.TextTransparency = 0.9
            wait(W)
            IntroText.TextStrokeTransparency = 1
            IntroText.TextTransparency = 1
            wait(W)
            IntroText.TextStrokeTransparency = 0.9
            IntroText.TextTransparency = 0.9
            wait(W)
            IntroText.TextStrokeTransparency = 0.8
            IntroText.TextTransparency = 0.8
            wait(W)
            IntroText.TextStrokeTransparency = 0.7
            IntroText.TextTransparency = 0.7
            wait(W)
            IntroText.TextStrokeTransparency = 0.6
            IntroText.TextTransparency = 0.6
            wait(W)
            IntroText.TextStrokeTransparency = 0.5
            IntroText.TextTransparency = 0.5
            wait(W)
            IntroText.TextStrokeTransparency = 0.4
            IntroText.TextTransparency = 0.4
            wait(W)
            IntroText.TextStrokeTransparency = 0.3
            IntroText.TextTransparency = 0.3
            wait(W)
            IntroText.TextStrokeTransparency = 0.2
            IntroText.TextTransparency = 0.2
            wait(W)
            IntroText.TextStrokeTransparency = 0.1
            IntroText.TextTransparency = 0.1
            wait(W)
            IntroText.TextStrokeTransparency = 0
            IntroText.TextTransparency = 0
            wait(2)
            IntroText.Text = 'Loading...'
                        wait(W)
            IntroText.TextStrokeTransparency = 0.1
            IntroText.TextTransparency = 0.1
            wait(W)
            IntroText.TextStrokeTransparency = 0.2
            IntroText.TextTransparency = 0.2
            wait(W)
            IntroText.TextStrokeTransparency = 0.3
            IntroText.TextTransparency = 0.3
            wait(W)
            IntroText.TextStrokeTransparency = 0.4
            IntroText.TextTransparency = 0.4
            wait(W)
            IntroText.TextStrokeTransparency = 0.5
            IntroText.TextTransparency = 0.5
            wait(W)
            IntroText.TextStrokeTransparency = 0.6
            IntroText.TextTransparency = 0.6
            wait(W)
            IntroText.TextStrokeTransparency = 0.7
            IntroText.TextTransparency = 0.7
            wait(W)
            IntroText.TextStrokeTransparency = 0.8
            IntroText.TextTransparency = 0.8
            wait(W)
            IntroText.TextStrokeTransparency = 0.9
            IntroText.TextTransparency = 0.9
            wait(W)
            IntroText.TextStrokeTransparency = 1
            IntroText.TextTransparency = 1
            wait(W)
            IntroText.TextStrokeTransparency = 0.9
            IntroText.TextTransparency = 0.9
            wait(W)
            IntroText.TextStrokeTransparency = 0.8
            IntroText.TextTransparency = 0.8
            wait(W)
            IntroText.TextStrokeTransparency = 0.7
            IntroText.TextTransparency = 0.7
            wait(W)
            IntroText.TextStrokeTransparency = 0.6
            IntroText.TextTransparency = 0.6
            wait(W)
            IntroText.TextStrokeTransparency = 0.5
            IntroText.TextTransparency = 0.5
            wait(W)
            IntroText.TextStrokeTransparency = 0.4
            IntroText.TextTransparency = 0.4
            wait(W)
            IntroText.TextStrokeTransparency = 0.3
            IntroText.TextTransparency = 0.3
            wait(W)
            IntroText.TextStrokeTransparency = 0.2
            IntroText.TextTransparency = 0.2
            wait(W)
            IntroText.TextStrokeTransparency = 0.1
            IntroText.TextTransparency = 0.1
            wait(W)
            IntroText.TextStrokeTransparency = 0
            IntroText.TextTransparency = 0
            wait(2)
        end
    else
        if AOP.Value == 2 then
            BlueEffect.Size = 0
            wait(2)
            IntroText.Text = 'Ready?'
            wait(2)
            IntroText.Text = 'Set?'
            wait(2)
            IntroText.Text = 'FIGHT!'
            wait(2)
            IntroText.Visible = false
            wait(W)
            BattleFrame.Visible = true
        end
    end
end)

Now, I know you can change the transparency into a loop but I have no idea ;-;. So I'm requesting assistance please!

Also, when I join the server (actually playing) The IntroText is still visible but the blur is gone.

I need some help please ;)

Thank you for any help or support!

0
You could use a loop for the transparency changing RockerCaleb1234 282 — 6y
0
I know but I'm not sure how so I need help. BlackOrange3343 2676 — 6y
0
this code pains my soul Perci1 4988 — 6y
0
sorry Percil BlackOrange3343 2676 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

You can make the code cleaner and shorter using the for do generic loop.

The loop can replace the "while true do" loop and instead be faster, but in this case if you want it to be infinite, just place the loop in the "while true do" loop instead.

The loop works like this:

FIRST NUMBER: Starting number to count at.

SECOND NUMBER: Number to count to.

THIRD NUMBER: Number to count by.

for i = 0.1, 1, 0.1 do
    IntroText.TextStrokeTransparency = i
    IntroText.TextTransparency = i
    wait(W)
end
for i = 1, 0, -0.1 do
    IntroText.TextStrokeTransparency = i
    IntroText.TextTransparency = i
    wait(W)
end

You can choose to replace this with the "while true do" loop if you don't need it to be infinite, otherwise place it inside that loop for it to be infinite.

Also, you don't need to make a loading screen that doesn't even load anything. Incorporate real loading for example waiting for the character to load or waiting for instances to be available.

(Player.CharacterAdded:wait(), :WaitForChild(object or string value))

Please feel free to ask me anything for help with scripting! Of course, I won't make the script.

_________________________________________

EDIT: Because you asked, you can use break (lower-case sensitive) to destroy a loop or function!

0
It's loading as waiting for a player but thanks for you answer! will be accepted tomorrow! BlackOrange3343 2676 — 6y
0
Also is there anyway to stop a loop? BlackOrange3343 2676 — 6y
0
You can break a loop using "break". Almost everything is case-sensitive including somehow :Connect() and :FindFirstChild(), so make sure you lower-case "break". User#18043 95 — 6y
0
I id what you did but my script isn't even runnng noww BlackOrange3343 2676 — 6y
0
check for errors User#18043 95 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I'm not 100% sure if this is what you were looking for, but from my understanding of loops, this should work. Tweak it as you please. If this helped you dont forget to accept it as an answer

local teamForFirstGuy
local BlueSpawn = game.Workspace:WaitForChild('BlueTower').BlueSpawn
local RedSpawn = game.Workspace:WaitForChild('RedTower').RedSpawn
local AOP = game.ServerStorage:WaitForChild('AmountOfPlayers')
local BlueEffect = game.Lighting:WaitForChild('Blur')
local W = 0.07

game.Players.PlayerAdded:connect(function(plr)
    wait(W)
    AOP.Value = AOP.Value + 1

    local Stats = Instance.new('Model')
    Stats.Name = 'PlrStats'
    Stats.Parent = plr


    local Team = Instance.new("StringValue")
    Team.Name = "Team"

    if teamForFirstGuy then
        Team.Value = teamForFirstGuy == "Blue" and "Red" or "Blue"
    else
        Team.Value = math.random() < .5 and "Blue" or "Red"
        teamForFirstGuy = Team.Value

        Team.Parent = Stats

        plr.CharacterAdded:Connect(function(char)
            if Team.Value == 'Red' then
                wait()
                char:WaitForChild('HumanoidRootPart').CFrame = BlueSpawn.CFrame
            else
                wait()
                char:WaitForChild('HumanoidRootPart').CFrame = RedSpawn.CFrame
            end
        end)    
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    local IntroText = plr.PlayerGui:WaitForChild('MainGui').LoadingLabel
    local BattleFrame = plr.PlayerGui:WaitForChild('MainGui').BattleFrame

    if AOP.Value == 1 then
        BlueEffect.Size = 24
        IntroText.Visible = true
        while true do
            wait(2)
            IntroText.Text = 'Need One More Player!'
            wait(W)
            local i = IntroText.TextStrokeTransparency
            local d = IntroText.TextTransparency
            while i < 1 do
                i = i + 0.1
                d = d + 0.1
            end        
            wait(W)
            while i > 0 do
                i = i - 0.1
                d = d - 0.1
            end
            IntroText.Text = "Loading..."
            wait(W)
            while i < 1 do
                i = i + 0.1
                d = d + 0.1
            wait(W)
            while i > 1 do
                i = i - 0.1
                d = d - 0.1
        end
    else
        if AOP.Value == 2 then
            BlueEffect.Size = 0
            wait(2)
            IntroText.Text = 'Ready?'
            wait(2)
            IntroText.Text = 'Set?'
            wait(2)
            IntroText.Text = 'FIGHT!'
            wait(2)
            IntroText.Visible = false
            wait(W)
            BattleFrame.Visible = true
        end
    end
end)
0
You should use a for loop for the fading effect. hiimgoodpack 2009 — 6y
0
hiimgoodpack maybe you can do dat? BlackOrange3343 2676 — 6y
Log in to vote
0
Answered by 6 years ago

add these two functions at the beginning of your script

function appear(label)
    for i = 1, 0, -.1 do
        label.TextTransparency = i
        label.TextStrokeTransparency = i
        wait()
    end
end 


function disappear(label)
    for i = 0, 1, .1 do
        label.TextTransparency = i
        label.TextStrokeTransparency = i
        wait()
    end
end 

and then replace the waste of lines

local teamForFirstGuy
local BlueSpawn = game.Workspace:WaitForChild('BlueTower').BlueSpawn
local RedSpawn = game.Workspace:WaitForChild('RedTower').RedSpawn
local AOP = game.ServerStorage:WaitForChild('AmountOfPlayers')
local BlueEffect = game.Lighting:WaitForChild('Blur')
local W = 0.07

game.Players.PlayerAdded:connect(function(plr)
    wait(W)
    AOP.Value = AOP.Value + 1

    local Stats = Instance.new('Model')
    Stats.Name = 'PlrStats'
    Stats.Parent = plr


    local Team = Instance.new("StringValue")
    Team.Name = "Team"

    if teamForFirstGuy then
        Team.Value = teamForFirstGuy == "Blue" and "Red" or "Blue"
    else
        Team.Value = math.random() < .5 and "Blue" or "Red"
        teamForFirstGuy = Team.Value

        Team.Parent = Stats

        plr.CharacterAdded:Connect(function(char)
            if Team.Value == 'Red' then
                wait()
                char:WaitForChild('HumanoidRootPart').CFrame = BlueSpawn.CFrame
            else
                wait()
                char:WaitForChild('HumanoidRootPart').CFrame = RedSpawn.CFrame
            end
        end)    
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    local IntroText = plr.PlayerGui:WaitForChild('MainGui').LoadingLabel
    local BattleFrame = plr.PlayerGui:WaitForChild('MainGui').BattleFrame

    if AOP.Value == 1 then
        BlueEffect.Size = 24
        IntroText.Visible = true
        while true do
            wait(2)
            IntroText.Text = 'Need One More Player!'
            disappear(IntroText)
        appear(IntroText)
            wait(2)
            IntroText.Text = 'Loading...'
            wait(W)
            disappear(IntroText)
        wait(1)
        appear(IntroText)
            wait(2)
        end
    else
        if AOP.Value == 2 then
            BlueEffect.Size = 0
            wait(2)
            IntroText.Text = 'Ready?'
            wait(2)
            IntroText.Text = 'Set?'
            wait(2)
            IntroText.Text = 'FIGHT!'
            wait(2)
            IntroText.Visible = false
            wait(W)
            BattleFrame.Visible = true
        end
    end
end)

change it up as you please and accept this answer if it worked please

Answer this question