I used these lines script it: I get the error on line 9, _G.gameplayers is defined in another script

cam = game.Workspace.CurrentCamera
local button = script.Parent:WaitForChild('Button')
local bar = script.Parent:WaitForChild('Bar')
local title = bar.Title
local prev = bar.Previous
local nextone = bar.Next

function get()
	for _, v in pairs(_G.gameplayers()) do
		if v.Name == title.Text then
			return(_)
		end
	end
end

local debounce = false
button.MouseButton1Click:connect(function()
	bar.Visible = true
	if debounce == false then
		debounce = true
		bar.Visible = true
		pcall(function()
			title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
			script.Parent.Close.Visible = true
		end)
	elseif debounce == true then
		debounce = false
		pcall(function()
			cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
		end)
		bar.Visible = false
	end
end)

prev.MouseButton1Click:connect(function()
	wait(0.1)
	local players = _G.gameplayers
	local num = get()
	local player = players[num-1]
	local playerr = players[#players]
	if not pcall(function()
		cam.CameraSubject = game:GetService('Players')[player].Character.Humanoid
	end) then
	cam.CameraSubject = game:GetService('Players')[playerr].Character.Humanoid
		
	end
	pcall(function()
		title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
	end)
end)

nextone.MouseButton1Click:connect(function()
	wait(0.1)
	local players = _G.gameplayers
	local num = get()
	local player = players[num+1]
	local playerr = players[1]
	if not pcall(function()
		cam.CameraSubject = game:GetService('Players')[player].Character.Humanoid
	end) then
	cam.CameraSubject = game:GetService('Players')[playerr].Character.Humanoid
		
	end
	pcall(function()
		title.Text = game.Players:GetPlayersFromCharacter(cam.CameraSubject.Parent).Name
	end)
end)

Click this to see how my studio looks like

4 comments

0

If there are mistakes like .Parent instead of script.Parent it's because of the website, I wrote that correctly :P

0

What error are you getting?

0

Try adding a: repeat wait() until _G.gameplayers() ~= nil

0

In what part of the script do I need to put that?