#I need help with a spectate system.
1 messages · Page 1 of 1 (latest)
Can you show the script please
Also if the script is a local script that could be another issue
Can you also help with my issue
I will try this then get back to you!
It wasnt a local script and here is the script local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local isPlaying = Instance.new("BoolValue")
isPlaying.Name = "isPlaying"
isPlaying.Value = false
isPlaying.Parent = player
local SpectateGui = game.StarterGui:WaitForChild("SpectateGui")
if isPlaying == false then
SpectateGui.Enabled = true
else
SpectateGui.Enabled = false
end
end)
It should be isPlaying.Value == false
Currently, you are checking if the instance itself (BooleanValue) is false, where you should be checking its Value attribute
It's probably cuz of the variable's name too lol, we've all been there
To make it cleaner, don't do == false. Instead, do if not isPlaying.Value then
When in your live test, try checking the status of your SpectateGui
Check if it really is enabled and that the GUI elements in it are visible and whatnot
So,
local SpectateGui = game.StarterGui:WaitForChild("SpectateGui")
if isPlaying.Value then
SpectateGui.Enabled = true
else
SpectateGui.Enabled = false
end
end)
That's the opposite. If isPlaying is true, it'll enable the SpectateGui
I'm assuming isPlaying is false when not in a round, right?
Yes
Then it should be if not isPlaying.Value then
The not negates the boolean, so true becomes false and vice versa
Or swap the False and true around?
Yup that too
Sure
Can you show your current code here as well?
The updated code of this one
OK
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local isPlaying = Instance.new("BoolValue")
isPlaying.Name = "isPlaying"
isPlaying.Value = false
isPlaying.Parent = player
local SpectateGui = game.StarterGui:WaitForChild("SpectateGui")
if isPlaying.Value then
SpectateGui.Enabled = false
else
SpectateGui.Enabled = true
end
end)
I'm guessing the one with the name frame is the spectateGui?
So it works, it appears when the player first joined since they're not in a round. Now you want it to disappear when a round starts?
I turned it on when I joined and i want it off when the round starts
** You are now Level 4! **
So people cant spectate others and see what they are doing
To do this autonomously you could add a :Changed listener to your isPlaying BooleanValue, so that whenever you update the value of you IsPlaying instance, it automatically changes it as well
Could you help me I dont know how as i am learning lua
Do something like this:
IsPlaying.Changed:Connect(function(newValue: boolean)
if isPlaying.Value then... -- etcetera
end)
To break it down...
IsPlaying.Changed is the event.
:Connect(someFunction) means that, whenever the value of IsPlaying changes, we run someFunction
** You are now Level 4! **
Now, whenever you do IsPlaying.Value = false or IsPlaying.Value = true, it'll automatically run our someFunction inside the :Connect(someFunction) connection
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local isPlaying = Instance.new("BoolValue")
isPlaying.Name = "isPlaying"
isPlaying.Value = false
isPlaying.Parent = player
local SpectateGui = game.StarterGui:WaitForChild("SpectateGui")
isPlaying.Changed:Connect(function(newValue: boolean)
if isPlaying.Value then
SpectateGui.Enabled = false
else
SpectateGui.Enabled = true
end)
?
Exactly 👍
Though, for the first bit, it won't run since you've already changed the value to false before you've set up the connection lol. Put it in a local function instead and use that
local function onIsPlayingChanged(isPlaying: boolean)
if isPlaying then
SpectateGui.Enabled = false
else
SpectateGui.Enabled = true
end)
end
isPlaying.Changed:Connect(onIsPlayingChanged) -- This tells roblox that, from this moment on, run onIsPlayingChanged when isPlaying.Value is updated
onIsPlayingChanged(false) -- We run it at the start too
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local isPlaying = Instance.new("BoolValue")
isPlaying.Name = "isPlaying"
isPlaying.Value = false
isPlaying.Parent = player
local SpectateGui = game.StarterGui:WaitForChild("SpectateGui")
local function onIsPlayingChanged(isPlaying: boolean)
if isPlaying then
SpectateGui.Enabled = false
else
SpectateGui.Enabled = true
end)
end
isPlaying.Changed:Connect(onIsPlayingChanged) -- This tells roblox that, from this moment on, run onIsPlayingChanged when isPlaying.Value is updated
onIsPlayingChanged(false) -- We run it at the start too
?
yup
Put them all inside .PlayerAdded.
How it still gives errors
You're missing a ) on your last end
?
You're also missing and end for your local function
You can figure it out, it's all simply syntax errors now. Understand each part of the code and organize it
The Gui still stays on
Looks good logically, but could do better in indenting and general beautifying.
Your problem now is you're getting the SpectateGui from the StarterGui, when you should get it from the player's PlayerGui.
Roblox simply clones what's in StarterGui into the player's PlayerGui, so with that in mind, in your code, it's like you're editing the blueprint rather than what the player has.
On line 8, instead of game.StarterGui, do player.PlayerGui
That worked.
Also there is an issue that doesnt break anything but is annoying could you help with that quickly(Still to do with spectate system)]
Nice. There's a much more optimized way of doing this though, which involves using localscripts to handle the toggling of the SpectateGui. Currently you're letting the server deal with the toggling of each player's gui, so it's not that efficient atm
I can't commit to helping, I suggest just creating another post and wait for another dev to check it out
Ok
whats up
I already fixed the issue BUT