END'S RUINING my GAME! PLEASE HELP

My script should work but ends are RUINING MY SCRIPT!

Please help, thank you.

hello. i made a script for spawning maps but the script isnt working. there are no errors so i tryed playing around with the ends and its hurting my brain. this is an hour in and i still cannot figure the issue out. (like i said im probably ending the wrong things at the wrong time etc)

script:

local buttons = game.ServerStorage.Folder:WaitForChild("Buttons")
buttons.Changed:Connect(function()
local RandomAM = game.ServerStorage:WaitForChild("Folder"):WaitForChild("RandomLevel")
print("...Hn/text/start/Map_Script by SakDevRblx. Using Script in any game other than H>Hostility<H is not premitted or given premission H> you can contact @Laggy Cat#4063 DiscH>ord {complete sequence[message.start]}")
	--------------------------------------------------------------------------------------------------------------------------------------------
	--------------------						-MAIN SCRIPT-											     --------------------
	--------------------------------------------------------------------------------------------------------------------------------------------
local buttons = game.ServerStorage.Folder:WaitForChild("Buttons")
	buttons.Changed:Connect(function()
		if buttons.Value <= 0 then  print("Please do something")
	--------------------


		--																																		--
		--															SETTINGS																			--
		--																																		--






		--Amount Of Floors--
		--------------------
		RandomAM.Value = 3
		--------------------



		--Floors--
		--------------------
		local Hospital = game.ServerStorage.MapHospital:Clone()
		--------------------
		local Facility = game.ServerStorage.MapOldFacility:Clone()
		--------------------
		local Wood = game.ServerStorage.WoodHallsMap:Clone()
		--------------------



		--Essential Configs--
		--------------------
		local GenA = game.ServerStorage:WaitForChild("Folder"):WaitForChild("GenA")
		--------------------
		local FloorLV = game.ServerStorage:WaitForChild("Folder"):WaitForChild("FloorLv")
		--------------------
		local FloorType = game.ServerStorage:WaitForChild("Folder"):WaitForChild("FloorType")
		--------------------
		local time = 40
		--------------------



		--Text Changers--
		--------------------
		local ChatText = game.StarterGui.Playergui.gens.Generators
		--------------------
		local Chat = game.StarterGui.Playergui.gens
		--------------------




			while wait(1) do
				if time == 0 then 

					--------------------------------------------------------------------------------------------------------------------------------------------
					--------------------						-Wood Halls-											     --------------------
					--------------------------------------------------------------------------------------------------------------------------------------------				
					if RandomAM.Value == 1 then FloorType = 1

						--------------------
						--Value of this floor--	
						--------------------
						--------------------------------------------------------------------------------------------------------------------------------------------			
						if FloorType == 1 then game.Workspace.WoodHallsMap.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Wood.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						elseif FloorType == 2 then game.Workspace.MapHospital.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Wood.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						elseif FloorType == 3 then game.Workspace.MapOldFacility.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Wood.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						else 
							Wood.Parent = game.Workspace
							GenA.Value = GenA.Value + 2
							buttons.Value = GenA.Value
						end










						--------------------------------------------------------------------------------------------------------------------------------------------
						--------------------						-Hospital-											     --------------------
						--------------------------------------------------------------------------------------------------------------------------------------------				
					elseif RandomAM.Value == 2 then FloorType = 2

						--------------------
						--Value of this floor--	
						--------------------
						--------------------------------------------------------------------------------------------------------------------------------------------			
						if FloorType == 1 then game.Workspace.WoodHallsMap.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Hospital.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						elseif FloorType == 2 then game.Workspace.MapHospital.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Hospital.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						elseif FloorType == 3 then game.Workspace.MapOldFacility.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Hospital.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						else 
							Hospital.Parent = game.Workspace
							GenA.Value = GenA.Value + 2
							buttons.Value = GenA.Value
						end






						--------------------------------------------------------------------------------------------------------------------------------------------
						--------------------						-Facility-											     --------------------
						--------------------------------------------------------------------------------------------------------------------------------------------	
					elseif RandomAM.Value == 3 then FloorType = 3			

						--------------------
						--Value of this floor--	
						--------------------
						--------------------------------------------------------------------------------------------------------------------------------------------			
						if FloorType == 1 then game.Workspace.WoodHallsMap.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Facility.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						elseif FloorType == 2 then game.Workspace.MapHospital.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Facility.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------	
						elseif FloorType == 3 then game.Workspace.MapOldFacility.Parent = nil for _, scr in pairs(game.Workspace.SpawnedGeneratorFor:GetDescendants()) do scr.Parent = nil
								Facility.Parent = game.Workspace
								GenA.Value = GenA.Value + 2
								buttons.Value = GenA.Value
							end
							--------------------------------------------------------------------------------------------------------------------------------------------					
						else 
							Facility.Parent = game.Workspace
							GenA.Value = GenA.Value + 2
							buttons.Value = GenA.Value
						end
					end
				--------------------------------------------------------------------------------------------------------------------------------------------
				--------------------						-TIMER-								      			     --------------------
				--------------------------------------------------------------------------------------------------------------------------------------------
		else
			local ChatText = game.StarterGui.Playergui.gens.Generators
			
			ChatText.Text = "Elevator Leaving in "..tostring(time)
			print(time)
			time = time - 1
		end
	end
		end
	end)
end)

SIDE NOTE: when the button value goes to 0 it does nothing

1 Like

I think it’s not working because you are ending your if statements before you can run “else” or “elseif”

when i try to remove end it errors expected to close

Is this a localscript or a regular script? Also, you need to use Player.PlayerGui instead of StarterGui in the code.

this is a regular script located in game.serverscriptservice

Does it ever print “Please do something”?

yes it does print “Please do something.”

You have an excessive amount of end statements, you only need one end after the else to close off the if statement.

He’s actually put do statements after every if statement(you shouldn’t do that), and Studio doesn’t highlight anything.

Is there anything else in the output?

by the way whats happening is when the player gets the buttons value to 0 then start a 40 second timer then reload a new map. when it reloads a new map check if a previous map was loaded and delete it. theres a seperate thing called like generatorspawn something so i loop in workspace to delete all of them before spawning map

1 Like

Honestly I’d recommend redoing the code structure here, that’s probably causing all of the problems. See ROBLOX’s reference on if statements for a guide.

1 Like

it was working but today i decided to redo the code structure to be easier to add onto

1 Like

oh wait im getting another error:

PlayerGui is not a valid member of DataModel "Hostility @ 03 Jan 2022 01:34" - Server - MapGenerator:56

i think its reffering to this part of the code


		--Text Changers--
		--------------------
		local ChatText = game.PlayerGui.Playergui.gens.Generators
		--------------------
			local Chat = game.PlayerGui.Playergui.gens
		--------------------

how should i fix the error? @Judgy_Oreo

2 Likes

i think you need to put WaitForChild()

1 Like

It’s Player.PlayerGui, not game.PlayerGui

local Player = game:GetService("Players").Wseall_UTUBE

Player.PlayerGui.gens...

that will only get the player me

Yeah, so you can use remote events

--Script
ReplicatedStorage.Remotes.UpdateGensGui:FireAllClients("Hello")
--LocalScript
ReplicatedStorage.Remotes.UpdateGensGui.OnClientEvent:Connect(function(NewText)
    gens.Text = NewText
end)

so make a new remote event called UpdateGensGui and make a new local script located inside the textlabel then when i want to change text i say

ReplicatedStorage.Remotes.UpdateGensGui:FireAllClients(THE TEXT I WANT TO CHANGE)?

is my information correct? im unsure if im write i only think it

@Judgy_Oreo