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)
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.
elseif
instead of else if
wintime
not eight words of textInstance.new
requires a class. (line 43). It also has a second parameter for parent.workspace
is a short name for game.Workspace
script.Parent
is used 5 timesif a == b then c = b
is done a few times (eg line 8). Just say c = a
.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
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?