How do I make this LocalScript always repeat itself?

  1. What do you want to achieve?
    I would like this round script to repeat itself rather than doing what it does only once

  2. What is the issue?
    This script has a function in which it will make a gui pop up but it only happens once

  3. What solutions have you tried so far?
    I tried using repeat but that would display an error. I also tried while loops (while true do and while wait() do) But they would not do anything

Here is the script

local endGui = script.Parent.Parent.PlayerGui:WaitForChild("EndGui")
local gameInfo = endGui:WaitForChild("GameInfo")
local inRound = game.ReplicatedStorage.InRound

inRound.Changed:Connect(function()
	if inRound.Value == false then
		gameInfo.Visible = true
	end
end)
2 Likes

set the screengui to not resetonspawn

Do you get any errors in the Output window?

Do you set inRound.Value to true anywhere? If it’s still false that could explain why the script isn’t doing anything.

resetonspawn is already set to off

There are no errors in the output and value is set to true whenever the timer resets

I’d recommend using :GetPropertyChangedSignal('') function which launches your function detecting when an exact property of an instance changed.

Also, you should check if the value is change to the whole server and also the client so it does not cause any problems.

So I do it like this?

inRound:GetPropertyChangedSignal('inRound'):Connect(function()

No, when using that function, in the string you should put the name of any property that this instance has, in this case, you should put 'Value'.

Thanks but the error is still there and yes, the value changes on both server and client

There is no need to make a loop using while do or repeat until, you just need (as someone said) :GetPropertyChangedSignal("").

But at least from what I see your problem is in the function. You’re just setting Visible = true when Value == false once, but you’re not switching off back in any moment nor checking for it. If the value is controlled by the server and it is timed, there shouldn’t be any problem on directly setting the Visible property to the Value.

gameInfo.Visible = inRound.Value
2 Likes

But that changes visible to false because inRounds value is also false

Yeah, but in that case it is obvious that your script won’t repeat. It’s like buying an apple, eating it and not buying another one, you can’t pretend to keep eating if you don’t buy another one.

You can’t set the value to true and just let it on true and pretend it will switch back to false for some magic reason. At some point, I don’t know at which one specifically (it depends on what you’re looking for) you’ll have to switch that thing off

The gui has a play button which automatically sets gameinfo visible to false once clicked

You can use this line of code for a loop(or use RunService) and is more convenient because when the Value is true then it will show your gui and vise versa.

And write this:

local RS = game:GetService('RunService')
local ui_object
local inRound

RS.Stepped:Connect(function()
 ui_object.Visible = inRound.Value 
end)

inRound value is set to true whenever a round is happening so it would make the gui pop up during the round

Well, in this case (not pretending to be rude but…) it seems like a logic problem more than a coding one and I don’t really think there’s a concrete way for us to help you without getting some explicit info.

The thing is the following: if you want to switch on a gui when players are not in a round, the actual code is ok, if you want the gui to switch off when the player is in a round, add an extra:

else
   gameInfo.Visible = false

These calls will automatically fire when the value changes and you won’t have to do nothing more other than switching the inRound value.

1 Like

Then you should use if instances like this:

local RS = game:GetService('RunService')
local ui_object
local inRound

RS.Stepped:Connect(function()
if inRound.Value == false then
 ui_object.Visible = true
else
 ui_object.Visible = false
end
end)

I don’t know how to help if you say things that you did not state in you post.

Your code does not say the same…

As you state in your code, the gui will pop up when the inRound value is set to false.

1 Like

Thanks! This was a huge problem in my game that I didnt know how to fix.