Problem with a button

I have a problem, whenever you die while spectating, when you respawn you cant open up the ui again


Client script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local SpectatingModule = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("SpectatingModule"))


local playerGui = player:WaitForChild("PlayerGui")
local mainUI = playerGui:WaitForChild("MainUI")
local spectateToggle = mainUI:WaitForChild("SpectateToggle")
local specFrame = mainUI:WaitForChild("SpectateFrame")
local trollsUI = mainUI:WaitForChild("TrollsUI")
local nameDisplay = specFrame:WaitForChild("PlayerName")


local function setMovementEnabled(enabled)
	local character = player.Character
	if not character then
		character = player.CharacterAdded:Wait()
	end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = enabled and 16 or 0
		humanoid.JumpPower = enabled and 50 or 0
		humanoid.AutoRotate = enabled
	end
end


local function toggleSpectateMode(isEnabled)
	
	specFrame.Visible = isEnabled
	trollsUI.Visible = isEnabled
	spectateToggle.Text =  "EXIT SPECTATE" or "SPECTATE"

	
	SpectatingModule.isSpectating = isEnabled

	
	setMovementEnabled(not isEnabled)

	if isEnabled then
		local target = SpectatingModule.getCurrentTarget()
		if target then
			nameDisplay.Text = target.Name
			SpectatingModule.updateCamera(target)
		end
	else
		nameDisplay.Text = player.Name
		SpectatingModule.updateCamera(player)
	end
end


local function fullReset()
	SpectatingModule.isSpectating = false
	SpectatingModule.spectateEnabled = true
	setMovementEnabled(true)
	SpectatingModule.updateCamera(player)
	SpectatingModule.setSpectateEnabled(false)
	specFrame.Visible = false
	trollsUI.Visible = false
	spectateToggle.Text = "SPECTATE"
	spectateToggle.Visible = true
end


fullReset()


spectateToggle.MouseButton1Click:Connect(function()
	if not player.Character then return end
	toggleSpectateMode(not SpectatingModule.isSpectating)
end)


specFrame.Left.MouseButton1Click:Connect(function()
	if SpectatingModule.isSpectating then
		local target = SpectatingModule.moveLeft()
		if target then
			nameDisplay.Text = target.Name
			SpectatingModule.updateCamera(target)
		end
	end
end)

specFrame.Right.MouseButton1Click:Connect(function()
	if SpectatingModule.isSpectating then
		local target = SpectatingModule.moveRight()
		if target then
			nameDisplay.Text = target.Name
			SpectatingModule.updateCamera(target)
		end
	end
end)






2 Likes

Screen Shot 2025-04-25 at 3.10.15 PM

Select the ScreenGui then check the Properties window to see if ResetOnSpawn is enabled.

3 Likes

Is it supposed to be enabled or disabled?

2 Likes

That’s up to you.

If you want everything “reset” then enable it.

4 Likes

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