I need help debugging multiple scripts

This is probably by far the hardest multi section scripts (for now) I’ve ever done and I need assistance debugging. I have tried multiple attempts (on my own) and I could just not figure out what is causing these problems.

Note: They are all server scripts.

View to see the scripts

For the first one, it’s name “DestroyScript”.

local StarterGui = game:GetService("StarterGui")
local ScreenGui = StarterGui.ScreenGui
local serverScript = ScreenGui.Frame.TextLabel.Script
local serverScript2 = ScreenGui.Frame.TextLabel.DestroyScript

task.wait(6)
print("ACTIVATING SCRIPT")
serverScript.Enabled = true
ScreenGui.Enabled = true
serverScript2.Enabled = false

The other script that is causing a problem is a workspace script.

local StarterGui = game:GetService("StarterGui")
local ScreenGui = StarterGui.ScreenGui
local serverScript = ScreenGui.Frame.TextLabel.Script
local serverScript2 = ScreenGui.Frame.TextLabel.DestroyScript
local sound = workspace["Bensley - Vex"]

local function SCRIPTACTIVATION()
	if serverScript.Disabled == true and serverScript2.Disabled == false then
		local plrs = game.Players:GetPlayers()
		for _, plr in pairs (game.Player:GetPlayers()) do
			plr.Character.Humanoid.Health = 0
		end
		workspace.SpawnLocation.Enabled = false
		workspace.SpawnLocation2.Enabled = true
		sound:Play()
	else
		print("NOT ACTIVE.")
		task.wait(1)
	end
end

while true do
	task.wait(0.05)
	SCRIPTACTIVATION()
end

Here’s a video demonstration of my issue as of right now.

For context, I’m trying to get the workspace script (The 2nd one) to only run when both “DestroyScript” and Script in StarterGui.ScreenGui.Frame.TextLabel are disabled. DestroyScript works but it doesn’t enable the ScreenGui at all or even let alone the workspace script run. The workspace script runs instantly and assumes that both “serverScript” (The disabled script in StarterGui) and “serverScript2” (The first script in the view to see scripts) are both disabled instantly, causing it to run immediately, which is not what I want.

For context of what I’m trying to make, I’m trying to make 3 scripts that first, the workspace script will detect when 2 scripts are completely disabled so it can run, disable the first spawn location and enable the other one, killing the players immediately after the 2nd script (Script in StarterGui.ScreenGui.Frame.TextLabel) is disabled as the “DestroyScript” is also disabled.

The problem is, the workspace script (the 2nd one) immediately runs upon a player joining and bugs at when the player dies (which also needs debugging at line 10) and “DestroyScript” refuses to enable ScreenGui (Which is seen in the video I posted, when it prints SCRIPT ACTIVATED but does not show the ScreenGui). I’d like it if anybody told me what the issue was and help me debug the scripts, as I tried to do it multiple times (around 20 times) from changing to LocalScripts to ServerScripts, which made things worse and now I would like to just stay at ServerScripts, because the Gui is global for everyone and the event of players being killed to respawn to the 2nd spawn location is intentional. Please help. Thanks!

1 Like

Dunno if this resolves all the issues, but this is definitely a major factor:

for _, plr in pairs (game.Player:GetPlayers()) do

should be

for _, plr in pairs (game.Players:GetPlayers()) do

The service is Players, not Player

(10th line of second script)

1 Like

Second issue is trying to modify the player’s UI / scripts in their UI, by modifying StarterGui.

Once the player joins the game, they will access StarterGui once, but never again. After that point, the UI can be found in game.Players.PLAYERNAME.PlayerGui.

To modify something in all players’ UI, you can loop through them:

for _, Player in ipairs(game.Players:GetPlayers()) do
    local ScreenGui =  Player.PlayerGui.ScreenGui
    local serverScript = ScreenGui.Frame.TextLabel.Script
    local serverScript2 = ScreenGui.Frame.TextLabel.DestroyScript

    serverScript.Enabled = true
    ScreenGui.Enabled = true
    serverScript2.Enabled = false
end
1 Like

I’d like to say something since I forgot to do something about the post in the last 16 hours.

I had already received help on the issue on the public DevForum server, which my issue is currently solved and everything that I desire in these scripts are fully functioning.

I thank you for helping me, even if nobody responded and the post was 10+ hours old. Although, I received help in the public DevForum server after 1 hour I posted this post because nobody was responding. I’m sorry for the inconvience however at the same time I thought nobody was going to respond to my DevForum post but seeing that someone like you responded gave me a hint that the DevForum community is truly supportive.

I thank you for your efforts to help me, but I already had the solution from asking somewhere else.

Sorry if I wasted your time, it was my fault since I didn’t want to spoonfeed the community or dare to close the post since I would have to flag the post in order to get it closed and moderation takes a long time.

Not sure if these kinds of replies are allowed but it’s worth the risk.