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! :)

local players = nil
local number = 1
local maxnumber = 0
local player = game.Players.LocalPlayer

-- Broken Script Below
if player.Lobby then player.PlayerGui.SpectateGui = true
else player.PlayerGui.SpectateGui = false
end
-- Broken Script Above



script.Parent.Next.MouseButton1Click:connect(function(right)
    players = game.Players:GetChildren()
    number = number + 1
    if players[number] ~= nil then
        game.Workspace.CurrentCamera.CameraSubject = players[number].Character.Humanoid
        if players[number].Name ~= player.Name then
            script.Parent.PlayerName.Text = players[number].Name
        else 
            script.Parent.PlayerName.Text = "Nobody"
        end
    elseif players[number] == nil then
        number = 1
        game.Workspace.CurrentCamera.CameraSubject = players[number].Character.Humanoid
        if players[number].Name ~= player.Name then
            script.Parent.PlayerName.Text = players[number].Name
        else 
            script.Parent.PlayerName.Text = "Nobody"
        end
    end
end)

script.Parent.Previous.MouseButton1Click:connect(function(left)
    players = game.Players:GetChildren()
    maxnumber = #players
    number = number - 1
    if players[number] ~= nil then
        game.Workspace.CurrentCamera.CameraSubject = players[number].Character.Humanoid
        if players[number].Name ~= player.Name then
            script.Parent.PlayerName.Text = players[number].Name
        else 
            script.Parent.PlayerName.Text = "Nobody"
        end
    elseif players[number] == nil then
        number = maxnumber
        game.Workspace.CurrentCamera.CameraSubject = players[number].Character.Humanoid
        if players[number].Name ~= player.Name then
            script.Parent.PlayerName.Text = players[number].Name
        else 
            script.Parent.PlayerName.Text = "Nobody"
        end
    end
end)

script.Parent.Parent.SpectateButton.Spectate.MouseButton1Down:connect(function(click)
    if script.Parent.Parent.Active.Value == false then
        script.Parent.Parent.Active.Value = true
        script.Parent.Parent.ChangePlayer.Visible = true
    elseif script.Parent.Parent.Active.Value == true then
        script.Parent.Parent.Active.Value = false
        script.Parent.Parent.ChangePlayer.Visible = false
        script.Parent.PlayerName.Text = "Nobody"
        number = 1
        game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    end
end)

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:

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

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


playing.Value = true

Inside my Spectate local script I have:


local players = nil local number = 1 local maxnumber = 0 local player = game.Players.LocalPlayer local replicatedstorage = game:GetService('ReplicatedStorage') local playing = replicatedstorage:WaitForChild('Playing') local PlayerGui = game:GetService('PlayerGui') local spectatemode = PlayerGui:WaitForChild('SpectateGui') if playing.Value == false then spectatemode.enabled = true else if playing.Value == true then spectatemode.enabled = false --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