Player.CharacterAdded not working and not enabling my menu gui!

Hello, Im trying to make a menu system for the first time and have came into a roadblock of a problem that I tried looking up the answer to and couldnt find anything… I am trying to enable the gui and music through a local script, but it isnt working neither is wait:().

Help is appreciated :smiley:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player.PlayerGui
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local MenuCamera = workspace:WaitForChild("MenuCamera")

local MenuGui = playerGui:WaitForChild("MainMenuGui")

player.CharacterAdded:Connect(function(character)
	wait(10)-- Wait for 10 seconds

	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = MenuCamera.CFrame

	MenuGui:wait() 

	MenuGui.Enabled = true
	MenuGui.MenuMusic:Play()
end)

3 Likes

I don’t see any errors except for on Line 11.

The colon ( : ) there is unnecessary, which causes an error. Try removing it and see if your code works.

If you get any errors in the console, please let me know.

Hope this helps!

1 Like

No sorry, that was a mistake of me editing that in after my bad :sob:
that still isnt the problem though unfortunatly.

2 Likes

When you play the game, open the console (F9 or type /console in chat), and let me know if you get any errors (any text that is highlighted in red).

2 Likes

nope nothing happens… What weird is I have a wiggle script and the one local script only works when the other one is enable and they have no correlation to them. something has to be bugged.

1 Like

Hmm, that’s weird. I also just noticed on line 16 that you tried to do “:wait()” on the MenuGui.
wait() does not exist so that may be stopping the script from working. Try removing that line.

Also, where is your LocalScript located?

1 Like

I removed that nothing happened, my scripts are located in starterplayerscripts. I tried move the scripts around and nothing happens. I think a bug is happening because the first script isnt working, but if I open the second one it works on that one.

first one:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player.PlayerGui
local camera = workspace.CurrentCamera
local MenuCamera = workspace:WaitForChild("MenuCamera")

local MenuGui = playerGui:WaitForChild("MainMenuGui")

player.CharacterAdded:Connect(function(character)
	
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = MenuCamera.CFrame

	-- Enable the GUI and play the music after the wait time
	MenuGui.Enabled = true
	MenuGui.MenuMusic:Play()
end)

second one:

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local MenuCamera = workspace:WaitForChild("MenuCamera")



repeat
	wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

-- Move cam
local maxTilt = 5
game:GetService("RunService").RenderStepped:Connect(function()
	camera.CFrame = MenuCamera.CFrame * CFrame.Angles(
		math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
		math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
		0
	)
end)

Oooooo iw found an error while disabling one of the scripts. It seems to be a cloud problem .

cloud_6514761722.UITools.Main.source.tools.properties:434: attempt to index number with ‘Value’ - Edit
21:10:22.689 Stack Begin - Studio
21:10:22.689 Script ‘cloud_6514761722.UITools.Main.source.tools.properties’, Line 434 - function set - Studio
21:10:22.689 Script ‘cloud_6514761722.UITools.Main.source.tools.properties’, Line 446 - function refresh - Studio
21:10:22.689 Stack End - Studio
21:10:22.919 cloud_6514761722.UITools.Main.source.tools.properties:434: attempt to index number with ‘Value’ - Edit
21:10:22.919 Stack Begin - Studio
21:10:22.919 Script ‘cloud_6514761722.UITools.Main.source.tools.properties’, Line 434 - function set - Studio
21:10:22.919 Script ‘cloud_6514761722.UITools.Main.source.tools.properties’, Line 446 - function refresh - Studio
21:10:22.919 Stack End - Studio

UItools is a plugin, maybe a virus is messing up my scripts…

I don’t really know what the problem is here. I will try to look more into it

that error wasnt causing it, its something to to with the CharacterAdded function because it wont wait unless the wait is outside the function…

Let’s see if removing the CharacterAdded event will do anything.

In the code below, the CharacterAdded event is removed and instead, we replace it with when the game is fully loaded.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player.PlayerGui
local camera = workspace.CurrentCamera
local MenuCamera = workspace:WaitForChild("MenuCamera")

local MenuGui = playerGui:WaitForChild("MainMenuGui")

game.Loaded:Connect(function()
	
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = MenuCamera.CFrame

	-- Enable the GUI and play the music after the wait time
	MenuGui.Enabled = true
	MenuGui.MenuMusic:Play()
end)

That did the same thing ughhhh, I updated the script and the menu is still not getting enabled…

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player.PlayerGui
local camera = workspace.CurrentCamera
local MenuCamera = workspace:WaitForChild("MenuCamera")
local mouse = player:GetMouse()
local MenuGui = playerGui:WaitForChild("MainMenuGui")


game.Loaded:Connect(function()

	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = MenuCamera.CFrame

	-- Enable the GUI and play the music after the wait time
	MenuGui.Enabled = true
	MenuGui.MenuMusic:Play()
end)


repeat
	wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

-- Move cam
local maxTilt = 5
game:GetService("RunService").RenderStepped:Connect(function()
	camera.CFrame = MenuCamera.CFrame * CFrame.Angles(
		math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
		math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
		0
	)
end)

 
   

I don’t really know what to tell you. I am not an advanced scripter so I just gonna let someone else try to help you.

okay! :+1: thanks for trying this problem Ive been working on to try to solve for at least an hour.

I added the enable line outside of the function and it worked!!!

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