What do you want to achieve?
i want to make a simple rounds system based on gnomecode’s tutorial video. only not in a while true do loop.
What is the issue?
ive got a gamestatusvalue and a timervalue in replicatedstorage, but at the beginning of the game the function on the server does get called to change the value in replicated storage to ‘game’ and the value does print as game, but the gui does not register that the value has changed (using the changed: even here) and does not change the texlabel
What solutions have you tried so far?
since the function gets called on the server and the value IS changed i thought it might be a loading/replication problem and the gui simply isn’t loaded when the server fires off the value change, or the value isnt loaded.but that wasn’t the case. trying to wait for gui and value was not successful, see:
for i , player in pairs(game:GetService("Players"):GetPlayers()) do
player.PlayerGui.ScreenGui:WaitForChild("gameStatusLabel")
end
wait(ReplicatedStorage.GameStatusValue)
wait(game:IsLoaded())
Can anyone help me make sense of this code? I really dont get it. thanksa lot in advance
ReplicatedStorage = game:GetService("ReplicatedStorage")
local timer = ReplicatedStorage.TimerValue
local gamestatus = ReplicatedStorage.GameStatusValue
for i , player in pairs(game:GetService("Players"):GetPlayers()) do
player.PlayerGui.ScreenGui:WaitForChild("gameStatusLabel")
end
wait(ReplicatedStorage.GameStatusValue)
wait(game:IsLoaded())
function BetweenGames()
gamestatus.Value = "Catnap" -- put for loop in co routine?
for i = 20, 0, -1 do
timer.Value = i
task.wait(1)
end
task.wait(20)
for index, player in pairs(game.Players:GetPlayers()) do
local character = player.Character or player.CharacterAdded:Wait()
character.HumanoidRootPart.CFrame = workspace.Cattree.SpawnPartCattree.CFrame
end
InGame()
end
function InGame()
print("ingame")
for index, player in pairs(game.Players:GetPlayers()) do
local character = player.Character or player.CharacterAdded:Wait()
character.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame
end
gamestatus.Value = "Game"
print(gamestatus.Value)
end
-- init
print("when is this printed?")
InGame()
-- above does not work at start of game,
--so the beginning status is default 'game'
--events
script.Parent.PlayerStats.RoundEnd.Event:Connect(BetweenGames)
gui client:
ReplicatedStorage = game:GetService("ReplicatedStorage")
local gamestatus = ReplicatedStorage:WaitForChild("GameStatusValue")
gamestatus.Changed:Connect(function()
print(gamestatus)
print("gamestatus changed!")
script.Parent.Text = gamestatus.Value
if gamestatus.Value == "Game" then
script.Parent.Parent.timerLabel.Visible = false
end
end)
You could try using :GetPropertyChangedSignal() with the values instead of .Changed on the client.
gamestatus:GetPropertyChangedSignal("Value"):Connect(function()
print("gamestatus changed: "..gamestatus.Value)
script.Parent.Text = gamestatus.Value
if gamestatus.Value == "Game" then
script.Parent.Parent.timerLabel.Visible = false
end
end)
EDIT: As for understanding the code, here is my best explanation I can offer.
Variables
Essentially, you are taking the variables timer and gamestatus and updating their values with the code that follows.
BetweenGames()
The BetweenGames() function updates the gamestatus value, which will update on the client as well because of the value:GetPropertyChangedSignal() event. The function then updates the timer value every second, counting down from 20. After 20 seconds of counting down, the script then waits 20 more seconds before continuing. (Is that a mistake?) After the function waits, it loops through every player in the game and gets their character, moving it to the next spawn location.
InGame()
The InGame() function loops through every player and gets their character, moving it to another spawn location. The function then updates the gamestatus value to “Game”. Print statements are self-explanitory.
Init
When the server starts, it will print “when is this printed?” and then the InGame() function is called.
I hope this helped. I am confused on whether or not you understand why the above code does not run at the start of the game. If you are still confused on this I can help you understand more.
thank you for your response! and thanks for your explanations. I tried this different event but it still doesnt work. I truly do not understand why…
(the 20 seconds wait after the teleport was a mistake yeah).
by all accounts the script should start with changing the value to ‘game’ and then the gui script should notice the change. but the gui label DOES change when the round ends (after three deaths). Why doesnt the first change happen? When i put in a wait it also doesnt work, which would rule out the gui(script) not being loaded/replicated. dont get it at all. ive disabled the resetonspawn for the screen gui so i can keep track of variables/lives. But dont think that should affect anything the first time round.
maybe i should just try to do this with a custom remote event… its just really strange.
Edit: below does actually work. i dont get it
ReplicatedStorage.ChangeGameStatusEventRemote:FireAllClients("Game")
ReplicatedStorage.ChangeGameStatusEventRemote.OnClientEvent:Connect(function(status)
print("gamestatus changed!")
script.Parent.Text = status
end)
EDIT: now it has stopped working again. whaaaaaaaaat is up with this?
edit: put another print in the game to see when the localscript fires first. and it does look like the localscript simply isn’t up and running sometimes yet, randomly. how do i fix that? because i’ve tried to wait for it but it didn’t work before.
putting below in the server script does nothing
what causes such a huge delay on the localscript replicating…
for i , player in pairs(game:GetService("Players"):GetPlayers()) do
player.PlayerGui.ScreenGui.gameStatusLabel:WaitForChild("ChangeGameStatus")
end
edit: i do not understand why such a simple implementation doesnt work for me. but i guess im forced to use collectionservice