Round script breaking after line 52

This is my roundscript. i made a function called TeleportPlayer that would teleport everyone to different positions in the game based on the position of parts in a folder. This script was working fine until I wrote this. The GUIs wont work but the tween and music will play, what did I do wrong? I dont see any errors in the Output.

local lobby = workspace.Lobby
local map = game.ReplicatedStorage.Maps.Map
local status = workspace.Values.Status
local inRound = workspace.Values.InRound

local backgroundSound = game.SoundService['2D'].Background

local intermission = workspace:WaitForChild("Lobby").Intermission.Sound
local puffs = workspace:WaitForChild("Lobby").Handle.Sound

intermission:Play()
intermission.Looped = true
puffs:Play()
puffs.Looped = true

while wait() do
	if inRound.Value == true then
		return
	end

	for i = 15, 0, -1 do
		status.Value = i
		wait(1.0)
	end

	intermission:Stop()
	puffs:Stop()

	inRound.Value = true
	lobby:Destroy()

	local clone = map:Clone()
	clone.Parent = workspace

	local teleportFolder = workspace:WaitForChild("Map").PlayerSpawns
	local teleportParts = teleportFolder:GetChildren()

	local Players = game:GetService("Players")

	local function TeleportPlayer(player)
		if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
			local randomSpawn = math.random(1, #teleportParts)
			local chosenSpawn = teleportParts[randomSpawn]
			player.Character.HumanoidRootPart.CFrame = chosenSpawn.CFrame
		end
	end

	for _, player in ipairs(Players:GetPlayers()) do
		TeleportPlayer(player)
	end

	local floorValue = workspace.Values.FloorValue
	floorValue.Value = floorValue.Value + 1

	local gui = game:GetService("StarterGui").Lobby.Intermission
	gui.Enabled = false

	local floorGui = game:GetService("StarterGui").InGame.Floor
	floorGui.Enabled = true

	local HealthBar = game.StarterGui.InGame.LocalHealth
	HealthBar.Enabled = true

	local Crystal = game.StarterGui.InGame.Crystal
	Crystal.Enabled = true

	local TweenService = game:GetService("TweenService")

	local part = workspace:WaitForChild("Map").Elevator.Door
	local endPosition = Vector3.new(112, -15.5, 99)

	local tween = TweenService:Create(part, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0), {Position = endPosition})
	tween:Play()

	backgroundSound:Play()

	script.Enabled = false
end
4 Likes

Does the floorValue instance exist in the workspace? If not, that’s probably the issue.

Yuh and like i said it was working perfectly until i wrote the function

Are you sure it was line 52? It could be the ‘TeleportPlayer’ function you embedded in the while wait thread.

bro read what i said

everything after line 52 doesnt work after i wrote that function

So everything that is after the ‘TeleportPlayer’ function does not work?

In Studio, inside the TeleportPlayer function, is the HRP teleporting itself? Or is it just staying at the character?

yea the function works perfectly but breaks the script

Try putting the variable for the ‘Players’ at the top, also sorry I have to head to bed, so I’ll be responding pretty late.

1 Like

In your teleport player function try to move the characters model rather than set the HRP.

player.Character:MoveTo(chosenSpawn.CFrame) or an older method player.Character:SetPrimaryPartCFrame(chosenSpawn.CFrame)

The teleport is working the function is breaking the script but ill try it anyways

Oh yeah so I ran the script again, so it’s the GUIs that arent working but the Tween is and the music is playing

1 Like

Ahh, you are only affecting the starter gui. Not the actual ui for the players. Each player gets their own copy under game.Players.LocalPlayer.PlayerGui (copied when they spawn in from whatever startergui is set to at the time). That’s what you need to effect. You should probably do the gui stuff in a local script and use a remote event to tell it when it should enable things or disable things.

1 Like

Remote events arent my strong suit but ill try it thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.