Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to disable script outside of Lobby? (repost)

Asked by 8 years ago

Hello!

I am re-posting this question, as there was no suggestions for my last question. I've tried additional methods in the days since, but have not had any success. Any help would be very much appreciated. :)

I have a Spectate mode script that works, everywhere, but I'd like it to only work while inside the Lobby.

Currently, I have the "ResetOnSpawn" box checked so that when a player dies in the game, the Spectate Mode is reset when they reappear in the Lobby, but if the player has it turned on while in the Lobby, when they teleport to the Game Map, Spectate Mode is still on.

Is there an easy way to do it? I know the code below is horribly wrong, but its where I've started. Any suggestions is appreciated. Thank you! :)

01local players = nil
02local number = 1
03local maxnumber = 0
04local player = game.Players.LocalPlayer
05 
06-- Broken Script Below
07if player.Lobby then player.PlayerGui.SpectateGui = true
08else player.PlayerGui.SpectateGui = false
09end
10-- Broken Script Above
11 
12 
13 
14script.Parent.Next.MouseButton1Click:connect(function(right)
15    players = game.Players:GetChildren()
View all 68 lines...

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

If you want, you can add a variable like,

specscript = false lobby = (whatever the lobby directory is)

while true do if the player is in lobby then specscript = true

else specscript = false end wait() end

then in the part of the script where this spectate thing is put,

if specscript == true then the spectate code else specscript = false

SORRY FOR NOT PUTTING THIS IN ACTUAL CODE, my studio isnt 'behaving' today

hope this helps :)

0
er...I'm pretty sure I broke my script. :D... local players = nil local number = 1 local maxnumber = 0 local player = game.Players.LocalPlayer local lobby = workspace:WaitForChild('Lobby') script.Parent = false while true do player.lobby = true end script.Parent = false if script.Parent == true then spectate script here else script.Parent = false end Never2Humble 90 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

I still can't get this to work properly. I've included a "Playing" bool value in Replicated Storage, and put this in my Main Script before the Lobby loads:

1local playing = replicatedstorage:WaitForChild('Playing')
2playing.Value = false

Then I have this line for after the player is teleported from the Lobby to the map:

1playing.Value = true

Inside my Spectate local script I have:

01local players = nil
02local number = 1
03local maxnumber = 0
04local player = game.Players.LocalPlayer
05local replicatedstorage = game:GetService('ReplicatedStorage')
06local playing = replicatedstorage:WaitForChild('Playing')
07local PlayerGui = game:GetService('PlayerGui')
08local spectatemode = PlayerGui:WaitForChild('SpectateGui')
09 
10if playing.Value == false then
11spectatemode.enabled = true
12else if playing.Value == true then
13spectatemode.enabled = false
14 
15--Below that is the Spectate script itself.

I receive this error when I try to test: 01:10:02.109 - Players.Player1.PlayerGui.SpectateGui.ChangePlayer.LocalScript:12: attempt to index local 'PlayerGui' (a nil value)

It renders the Spectate unplayable at that point. I've been adjusting this for a week, sometimes what I try has the Spectate mode open when the lobby loads and is playable at all times, other times its disabled for the first Lobby and first map, but once they're sent back tot he Lobby for the second time, its always enabled.

Answer this question