I'm using different values to control the game.
For example, if value A changes, value B is affected and so are a good amount of other things. Once A ends, B takes over and so on.
I have this laid out like so:
-Start -Reset -Race
There is also a value inside of every player called Participate.
A player will join the game, choose whether or not they would like to participate in the next race. If they select Yes, their value is turned to 1. Otherwise it remains 0 and they spectate.
Start happens when a race ends or a game starts and the lobby timers ticks down, allowing the players to buy items and choose whether or not they want to join the next race.
Reset happens when a race is over and teleports the players back the lobby. It also gets rid of the existing course.
Race happens when a race is in progress. The gui will say "A race is in progress" and spectating players have limited freedom during this time.
Basically these values change and that's how the game operates. Or so I thought. I can join a game and-
- The server does not work at all.
- In studio the only thing that works is the lobby. You can click yes or no and the gui text changes, but the timer never generates.
Can anybody help?
Here's the first script which takes care of the GUI's (not the timer) I'm planning to change these to on changed functions rather than endless loops.
local Yes = script.Parent.Yes
local No = script.Parent.No
local Timer = script.Parent.Timer
local Info = script.Parent.Info
local variable = Instance.new("NumberValue",game.Players.LocalPlayer)
variable.Name = "Participate"
function Participating() -- Participating feature inside of player
Yes.Visible = false
No.Visible = false
Info.Text = "You are participating in the next race!"
game.Players.LocalPlayer.Participate.Value = 1 -- Makes Yes/No invisible
end
Yes.MouseButton1Down:connect(Participating)
function Spectating()
Yes.Visible = false
No.Visible = false
Info.Text = "You are spectating the next race."
game.Players.LocalPlayer.Participate.Value = 0 -- Makes Yes/No invisible
end
No.MouseButton1Down:connect(Spectating)
if game.Players.LocalPlayer.Parent == game.Players then
wait(1)
print("Found Players")
while game.Players.LocalPlayer.Participate.Value == 0 and game.Workspace.Race.Value == 0 do
wait(0.05)
Info.Text = "You are spectating the next race." -- If player said no they are told this
end
end
while game.Players.LocalPlayer.Participate.Value == 1 and game.Workspace.Race.Value == 0 do -- If player said yes they are told this
wait(0.05)
Info.Text = "You are participating in the next race!"
end
Next is the main script which controls teleporting, the timer, and other various game controls.
function reset() -- Timer
local time = 60
for i = 1, 60 do
wait()
time = time - 1
script.Parent.Text = tostring(time)
end
game.Workspace.Start.Value = 1
game.Workspace.Race.Value = 1 -- When time runs out activate race/start values.
end
game.Workspace.Race.Value = 0
game.Workspace.Race.Changed:connect(function(value) -- Start of Game
if value == 0 then
wait(0.05)
reset()
game.StarterGui.ScreenGui.No.Visible = true
game.StarterGui.ScreenGui.Yes.Visible = true
end
end)
local reset = game.Workspace.Reset
reset.Changed:connect(function(value)
print(value)
if value == 0 then
for i, player in pairs(game.Players:GetChildren()) do
local Character = player.Character
Character:MoveTo(game.Workspace.Lobby.Position)
game.Players.LocalPlayer.PlayerGui.ScreenGui.Yes.Visible = true
game.Players.LocalPlayer.PlayerGui.ScreenGui.No.Visible = true
if game.Players.LocalPlayer.Participating.Value == 0 then
wait(5)
local time = 60
for i = 1, 60 do
wait()
time = time - 1
script.Parent.Text = tostring(time)
end
game.Workspace.Start.Value = 1
game.Workspace.Race.Value = 1
else
wait(0.05)
for i, player in pairs(game.Players:GetChildren()) do
local Character = player.Character
Character:MoveTo(game.Workspace.Lobby.Position)
reset()
game.StarterGui.ScreenGui.No.Visible = true
game.StarterGui.ScreenGui.Yes.Visible = true
game.Workspace.Reset.Value = 0
end
end
end
end
end)
local start = game.Workspace.Start -- Start of Race (This is what I edited)
start.Changed:connect(function(value)
print(value)
wait(0.05)
if value == 1 then
game.StarterGui.ScreenGui.No.Visible = false
game.StarterGui.ScreenGui.Yes.Visible = false
script.Parent.Parent.Info.Text = "Race in progress.."
for i, player in pairs(game.Players:GetChildren()) do
local Character = player.Character
if player.Participate.Value == 1 then
Character:MoveTo(game.Workspace.JetSki.VehicleSeat.Position) --The player will teleport
print("Teleported Players")
game.Workspace.Start.Value = 0
game.Workspace.Race.Value = 1
end
end
end
end)
