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

Able to help with a terminal script? [closed]

Asked by
IcyEvil 260 Moderation Voter
9 years ago

There spawns in 2 hints when it does the countdown 1 for defending team and 1 for raiding team...

Anyone able to help?

local wintime = 1200
local timegodown = 1 -- how many seconds of time go down for the term
local h = Instance.new("Hint")
script.Parent.Touched:connect(function(hit)
    if hit.Parent:findFirstChild("Humanoid") ~= nil then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            if player.TeamColor == BrickColor.new("Really black") then
                script.Parent.BrickColor = BrickColor.new("Really black")
                h.Parent = game.Workspace
                h.Text = "The Necromongers Own the Term!"
                wait(3)
                h:Remove()
            else
                if player.TeamColor == BrickColor.new("Really red") then
                script.Parent.BrickColor = BrickColor.new("Really red")
                h.Parent = game.Workspace
                h.Text = "The Raiders Own the Term!"
                wait(3)
                h:Remove()
            end
            while wait() do
                if script.Parent.BrickColor == BrickColor.new("Really black") then
                    h.Parent = game.Workspace
                        while wait(1.5) do
                            wintime = wintime-timegodown -- This assigns a new value to wintime each time thus dropping it by 1 each time giving you the result I believe you're looking for. 
                            h.Text = "The Necromongers have " .. wintime .. " seconds left before Winning!"
                            if h.Text == "The Necromongers have 0 seconds left before Winning!" then
                                h:Remove()
                                local m = Instance.new("Message")
                                m.Parent = game.Workspace
                                m.Text = "The Necromongers Have Won!"
                                wait(15)
                                m:Remove()
                            else
                                if script.Parent.BrickColor == BrickColor.new("Really red") then
                                    h.Parent = game.Workspace
                                    while wait(1.5) do
                                        wintime = wintime-timegodown
                                        h.Text = "The Raiders have ".. wintime .. " seconds left before Winning!"
                                        if h.Text == "The Raiders have 0 seconds left before Winning!" then
                                            h:Remove()
                                            local m = Instance.new()
                                            m.Parent = game.Workspace
                                            m.Text = "Raiders have Won!"
                                            wait(15)
                                            m:Remove()
                                        end
                                    end
                                end

                            end
                    end
                end
            end
        end
        end
    end
end)
1
So what exactly is the problem and where is the problem located? Perci1 4988 — 9y
0
Perci, I have no clue where the problem is, All I know is, is that it Makes 2 hints instead of Making 1, and changing it/ Deleting the first 1 to make a new one. IcyEvil 260 — 9y

Locked by BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

This code is terrible. The blocks of code are almost entirely completely wrong -- you have a while loop inside of a while loop (neither of which ever end) and blocks that are ten levels deep.

  • Tab your code correctly
  • Use elseif instead of else if
  • Compare wintime not eight words of text
  • Instance.new requires a class. (line 43). It also has a second parameter for parent.
  • workspace is a short name for game.Workspace
  • Use variables, e.g., script.Parent is used 5 times
  • if a == b then c = b is done a few times (eg line 8). Just say c = a.
  • You should use constants to refer to the team's colors
  • You should use a variable to refer to team name instead of typing out long strings twice
  • Checking for a Humanoid and that they are a player's character is redundant.

The while loop doesn't belong in the touched event...

Here is the best I could do.

local wintime = 1200
local timegodown = 1 -- how many seconds of time go down for the term
local h = Instance.new("Hint", workspace)
local model = script.Parent

local NECROS = game.Teams.Necromongers.TeamColor --BrickColor.new("Really black")
local RAIDERS = game.Teams.Raiders.TeamColor--BrickColor.new("Really red")

local importantHint = false

model.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        h.Parent = workspace
        local teamName = ""
        if player.TeamColor == NECROS then
            teamName = "Necromongers"
        elseif player.TeamColor == RAIDERS then
            teamName = "Raiders"
        end
        importantHint = true
        h.Text = "The " .. teamName .. " own the term!"
        model.BrickColor = player.TeamColor
        wait(3)
        importantHint = false
    end
end)

while wait(1.5) do
    local teamName
    if model.BrickColor == NECROS then
        teamName = "Necromongers"
    elseif model.BrickColor == RAIDERS then
        teamName = "Raiders"
    end
    if teamName then
        -- The point is one of the two colors?
        wintime = wintime - timegodown
        if not importantHint then
            h.Text = "The " .. teamName .. " have " .. wintime .. " seconds left before winning!"
        end
    end
    if wintime == 0 then
        h.Text = ""
        local m = Instance.new("Message", workspace)
        m.Text = "The " .. teamName .. " have won!"
        wait(15)
        m:Remove()
        break -- Stop this loop? Maybe?
    end
end
0
Thank you, Sorry for Messing that script Up So Badly... I am not that great of a scripter. IcyEvil 260 — 9y
Ad