Hey! I recently started my first game project but there has to be something I’m doing wrong. I’ve been writing most of my code because I don’t exactly know how to pass values into other scripts. For example there are local variables in one script, that I can’t use in other scripts so I just have a bunch of if statements and for loops in one entire script.
How can I keep my scripts more organized and use other scripts to do so?
Here is an example of my code…
I would have setting a players role, team, the intermission gui, rolegui, in the same script.
debounce = true
print(chosen.Name.. " is the DRAWER!")
chosen.Team = Teams.Drawer
for i, plr in ipairs(Players:GetChildren()) do
if plr ~= chosen then
plr.Team = Teams.Guessers
print(plr.Name.. " , you are a GUESSER!")
--delay(5, function()
plr:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.Visible = true
plr:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.DisplayRole.Text = "Guesser"
plr:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.DisplayRole.TextColor3 = Color3.fromRGB(43,121,125)
--end)
delay(15, function()
plr:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.Visible = false
end)
end
end
for i = 15, 1, -1 do
wait(1)
CurrentStatus.Value = "Intermission: "..i.. " seconds remaining"
Value = CurrentStatus.Value
RemoteEventNotInRound:FireAllClients(Value)
if i == 15 and chosen then
chosen:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.Visible = true
chosen:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.DisplayRole.Text = "Drawer"
chosen:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.DisplayRole.TextColor3 = Color3.fromRGB(43,121,125)
end
if i == 2 then
InRound = true
print("Round Started")
chosen:WaitForChild("PlayerGui"):WaitForChild("RoleGui").RoleFrame.Visible = false
if chosen then
local Brush = BrushTool:Clone()
Brush.Parent = chosen.Humanoid.Parent
end
while PlayersInServer < 2 do
task.wait()
NotEnoughPlayers()
end
while PlayersInServer >= 2 and InRound == true do
for i = 15, 1, -1 do
wait(1)
CurrentStatus.Value = i.. " seconds remaining"
Value = CurrentStatus.Value
RemoteEventInRound:FireAllClients(Value)
if i == 1 then
InRound = false
debounce = false
print("Round Ended")
for i, playerss in ipairs(Players:GetChildren()) do
playerss.Team = Teams.Neutral
end
while PlayersInServer < 2 do
task.wait()
NotEnoughPlayers()
end
end
end
end
end
end
end
end)
end)```