What do I want to achieve? So basically there is a hider and the others finders i want to start a timer for them
What is the issue? So basically the timer is acting weird i will show by a video -
What solutions have I tried so far? Yes I did but as i searched i did not find anything
So now i will show my code -
--Length Variables
local roundLength = game.ReplicatedStorage.roundLength
local gameStartLength = game.ReplicatedStorage.gameStartLength
game.Players.PlayerAdded:Connect(function(player)
wait(10)
-- Player Count
local playerCount = #game.Players:GetPlayers()
--Game Status
local gameStatus = game.ReplicatedStorage.gameStatus
gameStatus.Value = "Waiting for Game to Start..."
--Round Status
local roundStatus = player.PlayerGui:WaitForChild("InRound")
--Guis
local bgFinderHider = player.PlayerGui.Bg
local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui
--Texts
local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel
--Starting Game
while wait() do
--Checking if there are enough players to Start the Game
if playerCount >= 1 then
for i = gameStartLength.Value,0,-1 do
roundStatus.Value = false
wait(1)
gameStatus.Value = "Game Starts in "..i.." Seconds"
bgFinderHider.Enabled = false
end
-- choosing a hider from the players in the game
local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
print(hider.Name)
bgFinderHider.Enabled = true
finderHiderChoosingFrame:TweenPosition(
UDim2.new(0.258,0,0.2,0),
"In",
"Quad",
1,
false
)
--TypeWriter Function
local function typeWrite(object, text)
for i = 1,#text,1 do
wait(0.3)
object.Text = string.sub(text,1,i)
end
end
wait(2)
-- Checking if player is a hider or not and showing them the text
if player ~= hider then
typeWrite(hiderFinderText, 'Finder')
else
typeWrite(hiderFinderText, 'Hider')
end
wait(5)
finderHiderChoosingFrame:TweenPosition(
UDim2.new(0.258,0,1,0),
"Out",
"Quad",
1,
false
)
wait(1)
hiderFinderText.Text = ""
else
gameStatus.Value = "Waiting for Enough Players..."
end
end
end)
this script is inside severscriptservice just telling
You are running that code whenever a new player joins - so if 5 players have joined, youâre going to have the code for starting the game running 5 times.
can i replace the whole while loop inside in a for loop like this:
for player in pairs(game.Players:GetChildren()) do
-- Player Count
local playerCount = #game.Players:GetPlayers()
--Game Status
local gameStatus = game.ReplicatedStorage.gameStatus
gameStatus.Value = "Waiting for Game to Start..."
--Round Status
local roundStatus = player.PlayerGui:WaitForChild("InRound")
--Guis
local bgFinderHider = player.PlayerGui.Bg
local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui
--Texts
local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel
--Starting Game
while wait() do
--Checking if there are enough players to Start the Game
if playerCount >= 1 then
for i = gameStartLength.Value,0,-1 do
roundStatus.Value = false
wait(1)
gameStatus.Value = "Game Starts in "..i.." Seconds"
bgFinderHider.Enabled = false
end
-- choosing a hider from the players in the game
local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
print(hider.Name)
bgFinderHider.Enabled = true
finderHiderChoosingFrame:TweenPosition(
UDim2.new(0.258,0,0.2,0),
"In",
"Quad",
1,
false
)
--TypeWriter Function
local function typeWrite(object, text)
for i = 1,#text,1 do
wait(0.3)
object.Text = string.sub(text,1,i)
end
end
wait(2)
-- Checking if player is a hider or not and showing them the text
if player ~= hider then
typeWrite(hiderFinderText, 'Finder')
else
typeWrite(hiderFinderText, 'Hider')
end
wait(5)
finderHiderChoosingFrame:TweenPosition(
UDim2.new(0.258,0,1,0),
"Out",
"Quad",
1,
false
)
wait(1)
hiderFinderText.Text = ""
else
gameStatus.Value = "Waiting for Enough Players..."
end
end
end
when i used that with a for loop get children and get players, i got a error like:
22:15:01.976 ServerScriptService.RoundSystem:21: attempt to index number with âPlayerGuiâ - Server - RoundSystem:21
22:15:01.977 Stack Begin - Studio
22:15:01.977 Script âServerScriptService.RoundSystemâ, Line 21 - Studio - RoundSystem:21
22:15:01.977 Stack End - Studio
--Length Variables
local roundLength = game.ReplicatedStorage.roundLength
local gameStartLength = game.ReplicatedStorage.gameStartLength
while wait() do
for player in pairs(game.Players:GetPlayers()) do
wait(10)
-- Player Count
local playerCount = #game.Players:GetPlayers()
--Game Status
local gameStatus = game.ReplicatedStorage.gameStatus
gameStatus.Value = "Waiting for Game to Start..."
--Round Status
local roundStatus = player.PlayerGui:WaitForChild("InRound")
--Guis
local bgFinderHider = player.PlayerGui.Bg
local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui
--Texts
local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel
--Starting Game
while wait() do
--Checking if there are enough players to Start the Game
if playerCount >= 1 then
for i = gameStartLength.Value,0,-1 do
roundStatus.Value = false
wait(1)
gameStatus.Value = "Game Starts in "..i.." Seconds"
bgFinderHider.Enabled = false
end
-- choosing a hider from the players in the game
local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
print(hider.Name)
bgFinderHider.Enabled = true
finderHiderChoosingFrame:TweenPosition(
UDim2.new(0.258,0,0.2,0),
"In",
"Quad",
1,
false
)
--TypeWriter Function
local function typeWrite(object, text)
for i = 1,#text,1 do
wait(0.3)
object.Text = string.sub(text,1,i)
end
end
wait(2)
-- Checking if player is a hider or not and showing them the text
if player ~= hider then
typeWrite(hiderFinderText, 'Finder')
else
typeWrite(hiderFinderText, 'Hider')
end
wait(5)
finderHiderChoosingFrame:TweenPosition(
UDim2.new(0.258,0,1,0),
"Out",
"Quad",
1,
false
)
wait(1)
hiderFinderText.Text = ""
else
gameStatus.Value = "Waiting for Enough Players..."
end
end
end
end
Question, why is your typewriting script inside your Server script? Or am i reading that wrong?
I would use a IntValue instead, and have the server count it down. Then on the client,
local Value = game.ReplicatedStorage.Timer
local Object = YourTextLabel
local function typeWrite(object, text)
for i = 1,#text,1 do
wait(0.3)
object.Text = string.sub(text,1,i)
end
end
--The next function is to change the timer when it is needed.
Value.Changed:Connect(function() -- This is a basic example, what you would need to do is concentrate your string and number value. (Value.Value .. " is how much time is left")
typeWrite(Object, Value.Value)
end
The above code would only work if you changed the timer value on the serverside.
I know it isnt with the TypeWriter. Please read my above statement. It says that the script is for the Client to find when a value is changed by the serverside, and then update the playerâs GUI accordingly.
The issue is that something is making the TypeWrite function run more than once. That being said, i think you should try out my script. Therefore when the SERVER changes the timer value, the CLIENT notices only once. It then changes according to the time left in the value.
Bro listen, where that function call is like when the game chooses a person, a GUI appears and on that, a text is written with this effect. Now my problem is another like that GUI shows for only one person : /