UI is not working after respawn

Hi, so Im currently working on a Admin/Money System.
Everything works fine UNTIL I respawn the character. I tried now everything I could imagine. ResetOnSpawn is not changing anything. I put the LocalMainScript intoi StarterPlayerScripts (which made the menu open but interactions still dont work). I tried to copy the old ui on death into the playergui. But nothing worked.

-- ServerScript:
game.Players.PlayerAdded:Connect(function(plr)
	wait(2)
	Update()
	plr.Character.Humanoid.Died:Connect(function()
		local UI = plr.PlayerGui["Money/AdminSG"]:Clone()
		wait(game.Players.RespawnTime + 1)
		Update()
		UI.Parent = plr.PlayerGui
	end)
end)

function Update()
	rep.ModuleEvent:FireAllClients(Module.Whitelist, Module.Supporter, Module.Moderator, Module.Unlimited)
end

--LocalScript inside StarterPlayerScripts:

wait(1)
local UIS = game:GetService("UserInputService")
local repSto = game:GetService("ReplicatedStorage")
local rep = repSto:FindFirstChild("Money/AdminRS")




open = false
visible = false

local Unlimited = nil
local Moderator = nil
local Supporter = nil

local LocalPlayer = game.Players.LocalPlayer

local UI = LocalPlayer.PlayerGui["Money/AdminSG"].AdminPanel

local sound = UI.Denied
local Menu = UI.Menu
local MoneyMenu = UI.Money
local KickMenu = UI.Kick
local TeleportMenu = UI.Teleport
local BanMenu = UI.Ban
local SuperMenu = UI.SuperMenu
local Announcement = UI.Announcement
local Permissions = UI.Permissions

rep.ModuleEvent.OnClientEvent:Connect(function(White, Sup, Mod, UnLim)
	print(Sup)
	Supporter = Sup
	Moderator = Mod
	Unlimited = UnLim
	
	LocalPlayer = game.Players.LocalPlayer

	UI = LocalPlayer.PlayerGui["Money/AdminSG"].AdminPanel

	sound = UI.Denied
	Menu = UI.Menu
	MoneyMenu = UI.Money
	KickMenu = UI.Kick
	TeleportMenu = UI.Teleport
	BanMenu = UI.Ban
	SuperMenu = UI.SuperMenu
	Announcement = UI.Announcement
	Permissions = UI.Permissions
end)


UI.Parent.Money.Frame.Visible = true

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.F and not gameProcessedEvent then
		print("doubled")
		if table.find(Unlimited, LocalPlayer.Name) or table.find(Moderator, LocalPlayer.Name) or table.find(Supporter, LocalPlayer.Name) then
			print("good")
			if open == false then
				open = true
				Menu.Visible = true
				if table.find(Unlimited, LocalPlayer.Name) then
					SuperMenu.Visible = true
				end
			elseif Menu.Visible == true then
				open = false
				Menu.Visible = false
				SuperMenu.Visible = false
				Announcement.Visible = false
			end
		end
	end
end)

Menu.MoneyButton.MouseButton1Click:Connect(function()
	print("yes")
	if table.find(Unlimited, LocalPlayer.Name) then
		Menu.Visible = false
		SuperMenu.Visible = false
		MoneyMenu.Visible = true
	else
		Menu.MoneyButton.Text = "NOT HIGH ENOUGH RANK"
		sound:Play()
		wait(3)
		Menu.MoneyButton.Text = "Money"
	end
end)

After the respawn, the menu opens but I cant open further menus like the money menu.
The menu has now ResetOnSpawn on but like I said, its not making any difference.

9 Likes

That line is an attempt to fix the issue or was that before when you were editing the code?

game.Players.PlayerAdded:Connect(function(plr)
	wait(2)
	Update()
	plr.Character.Humanoid.Died:Connect(function()
		local UI = plr.PlayerGui["Money/AdminSG"]:Clone()
		wait(game.Players.RespawnTime + 1)
		Update()
		UI.Parent = plr.PlayerGui
	end)
end)
3 Likes

Try unticking ResetOnSpawn on the GUI.

5 Likes

Was an attempt to fix, before it just was a CharacterAdded function with Update() so almost the same with the difference that I didnt copied the UI

2 Likes

What does unticking mean and how can I do that?

1 Like

Click the ScreenGui and untick that in the Properties. It might work, I’m not too sure if I’m honest

4 Likes

You just have to uncheck the marker from ResetOnSpawn in your UI’s property.

2 Likes

I’d recommend placing the client-side code in a LocalScript parented to the Gui itself

You’ll need to slightly modify the code to reflect this change though

For this to work ResetOnSpawn needs to be set to true for the Gui

1 Like

Like I said, I tried that already and its not causing anything

1 Like

I tried that, but then my tables will reset to nil and when I try to update them again, like it worked when the player first joins the game, its not working for some reason

2 Likes

Another test you can try is placing the LocalScript inside of StarterCharacterScripts instead of StarterPlayerScripts

2 Likes

So I placed it again in the StarterGui and it works, BUT the table ckeck gives me an error but only when opening the MENU and not the otehr folder in it. So the event to update the tables isnt firing so it stays nil.

1 Like

That’s because when the player dies/resets, the values retrieved by the OnClientEvent are lost. You’ll need to store them somewhere external to the script like inside of a module or value Instance to be able to retrieve them again afterwards

2 Likes

Make sure the table exists, before using table.find().

1 Like

Ahhh so I found the error why the Update() function after the reset wasnt working. It was because I had a wait(1) on the beginning of the script so when the function got fired from the server, the client was still in the wait(1). Thanks for responding

4 Likes

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