I was tried to make UI play button for my menu. I added script (Local script) , but there is error in my script about LoadCharacter() - Players.Egor_Naum.PlayerGui.ChooseTeamGui.Play.PlayTextButton.ClickScript:6: attempt to index nil with 'LoadCharacter' . I tested ALMOST all stuff. How to fix?
script.Parent.MouseButton1Click:Connect(function(plr) if game.Players.LocalPlayer.TeamColor ~= BrickColor.new("Medium stone grey") then -- check if player choosed team (if (s)he not choosing team) game.Lighting.Blur.Size = 0 -- Makes blut size to 0 plr:LoadCharacter(plr) --Refresh character script.Parent.Parent.Parent.Enabled = false -- Makes GUI not enabled script.Parent.Parent.Parent.MenuMusic:Stop() -- Stops music game.Workspace.Camera.CameraType = Enum.CameraType.Custom -- Makes default (custom) camera print(game.StarterGui.ChooseTeamGui.ChooseTeam.Frame.Visible ) --If player dont choosed team (if (s)he choosign team -- else script.Parent.Parent.ChooseTeamWarning.TextTransparency = 0-- Makes warning text visible wait(1) script.Parent.Parent.ChooseTeamWarning.TextTransparency = 1-- Makes warning text invisible end end)
You are attempting to get the player from your function .MouseButton1Click(), however .MouseButton1Click does not create an output. Alternatively, you can use game.Players.LocalPlayer as you are using a LocalScript. Here is the API Reference for MouseButton1Click: https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click
local plr = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() if game.Players.LocalPlayer.TeamColor ~= BrickColor.new("Medium stone grey") then -- check if player choosed team (if (s)he not choosing team) game.Lighting.Blur.Size = 0 -- Makes blut size to 0 plr:LoadCharacter(plr) --Refresh character script.Parent.Parent.Parent.Enabled = false -- Makes GUI not enabled script.Parent.Parent.Parent.MenuMusic:Stop() -- Stops music game.Workspace.Camera.CameraType = Enum.CameraType.Custom -- Makes default (custom) camera print(game.StarterGui.ChooseTeamGui.ChooseTeam.Frame.Visible ) --If player dont choosed team (if (s)he choosign team -- else script.Parent.Parent.ChooseTeamWarning.TextTransparency = 0-- Makes warning text visible wait(1) script.Parent.Parent.ChooseTeamWarning.TextTransparency = 1-- Makes warning text invisible end end)
Hope this helps!