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

How could I link the wait time in the script to a gui , Help please?!

Asked by 6 years ago

Hi Guys , I have just created a Map Changer system along with a Round system. I wanted to ask how I could link the wait time in the script to show in a gui at the top of the screen , same goes with intermissions , How much time left for a round to end etc.... Here's my script! It works totally fine :

local players = game.Players:GetChildren()
local maps = game.Lighting.Maps:GetChildren()
local currentmap = game.Workspace:WaitForChild("CurrentMap")
local chosenmap = script:WaitForChild("ChosenMap")
local spawner = game.Workspace:WaitForChild("Spawn")
local choices = {}


function choosemap()
  for i = 1,#maps do
 if maps[i]:isA("Model")then
  table.insert(choices,maps[i])
 end
end
local picked = math.random(1,#maps)
chosenmap.Value = choices[picked].Name
end

--Load the map
function loadMap()
 local map = game.Lighting.Maps:FindFirstChild(chosenmap.Value)
 if map then
    local mapclone = map:Clone()
    mapclone.Parent = currentmap
    mapclone:SetPrimaryPartCFrame(CFrame.new(0,0,0))
  end
end



function deleteMap()
 for i,v in pairs(currentmap:GetChildren())do
  if v:isA("Model") then
   v:Destroy()
  end
 end
end


function teleportPlayers()
for i,v in pairs(game.Players:GetChildren())do
  v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame * CFrame.new(math.random(5,10),0,math.random(5,10))
  end
end


function teleportBack()
 for i,v in pairs(game.Players:GetChildren())do
  v.Character.HumanoidRootPart.CFrame = spawner.SpawnLocation.CFrame * CFrame.new(math.random(5,10),0,math.random(5,10))
 end
end


while true do
 wait(3)
 choosemap()
 loadMap()
 wait(1)
 teleportPlayers()
 wait(10)
 deleteMap()
 teleportBack()
end

2 answers

Log in to vote
0
Answered by 6 years ago

On line 60 you would change wait(10) to

--start "i" at 10 and subtract 1 each time until we reach 0
for i=ROUND_TIMER , 0, -1 do 
    print("Your GUI text would show: " .. i)
    wait(1)
end

and have

local INTERMISSION_TIMER = 3
local ROUND_TIMER = 10 

somewhere outside your while loop

Ad
Log in to vote
0
Answered by 6 years ago

I am not quite sure what the wait time that you are talking about is so I am going to assume that you mean the wait() functions in this part here

while true do
 wait(3)
 choosemap()
 loadMap()
 wait(1)
 teleportPlayers()
 wait(10)
 deleteMap()
 teleportBack()
end

To keep track of how much time is left to wait you can use a for loop the changes the value of a intvalue to the number of seconds remaining then have the players' gui read that intvalue and show it on screen

change your while true do loop to something like this where TimeRemaining is a IntValue Instance in the workspace

while true do
 for i=1,3 do
     workspace.TimeRemaining.Value = 3-i
     wait(1)
 end
 choosemap()
 loadMap()
 for i=1,1 do
     workspace.TimeRemaining.Value = 1-i
     wait(1)
 end
 teleportPlayers()
 for i=1,10 do
     workspace.TimeRemaining.Value = 10-i
     wait(1)
 end
 deleteMap()
 teleportBack()
end

then make a text label in the players' gui and have a script inside that looks something like this

workspace.TimeRemaining.changed:Connect(function(value)
    script.Parent.Text = "Time Left: "..value.." seconds"
end)

hope this helps

0
Changed not changed. how do you make errors User#19524 175 — 6y
0
I thought it might be that, I am not typing in studio and this website doesn't make autocorrect coding. justoboy13 153 — 6y

Answer this question