While creating a main menu for my combat game, i’ve run into a problem with :LoadCharacter() The problem is that when the player presses play and loads in, the gui is still on screen and the camera is stuck.
Here’s a video of the problem:
robloxapp-20230529-1537375.wmv (2.0 MB)
Here’s both the scripts I’m using:
Localscript - In the UI in ReplicatedStorage
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()
local DefaultCFrame = workspace.CameraPart.CFrame
local Scale = 160
local InMenu = true
local UI = script.Parent
local Buttons = UI.Buttons
local FadeFrame = UI:WaitForChild('FadeFrame')
local SpawnText = UI:WaitForChild('FadeFrame').Spawn
local MenuItems = UI:WaitForChild('Buttons')
local PlayButton = MenuItems:WaitForChild('Play')
local ModesButton = MenuItems:WaitForChild('Play')
local Modes = MenuItems:WaitForChild('Play')
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
1,
Enum.EasingStyle.Quart,
Enum.EasingDirection.Out,
0,
false,
0
)
local tweenInfo2 = TweenInfo.new(
0.8,
Enum.EasingStyle.Quart,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = tweenService:Create(FadeFrame, tweenInfo, {BackgroundTransparency = 0})
local tweenText = tweenService:Create(SpawnText, tweenInfo, {TextTransparency = 0})
local tween2 = tweenService:Create(FadeFrame, tweenInfo2, {BackgroundTransparency = 1})
local tweenText2 = tweenService:Create(SpawnText, tweenInfo2, {TextTransparency = 1})
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
game:GetService("RunService").Heartbeat:Connect(function()
Camera.Focus = DefaultCFrame
local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, -(Mouse.Y-Center.Y)/Scale, 0)
Camera.CFrame = DefaultCFrame * CFrame.Angles(math.rad(MoveVector.X), math.rad(MoveVector.Y), math.rad(MoveVector.Z))
Camera.FieldOfView = 83
end)
Camera.CFrame = workspace.CameraPart.CFrame
PlayButton.MouseButton1Click:Connect(function()
if InMenu then
InMenu = false
tween:Play()
tweenText:Play()
wait(5)
tween2:Play()
tweenText2:Play()
game.ReplicatedStorage.LoadChar:FireServer()
task.wait()
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Player.Character:WaitForChild("Humanoid")
end
end)
Script - In ServerScriptService
game.Players.PlayerAdded:Connect(function(Plr)
game.ReplicatedStorage.Spawn.Parent = Plr:WaitForChild("PlayerGui")
end)
local Camera = workspace.CurrentCamera
local characterLoader = game.ReplicatedStorage:WaitForChild("LoadChar")
local function loadCharacter(client)
if client then
if client.Character ~= nil then print(client.Name .. " already has character loaded, reloading")
else print(client.Name .. " had no character loaded, loading their character now!")
client:LoadCharacter()
end
end
end
characterLoader.OnServerEvent:connect(loadCharacter)
I’m a little stumped, I’m not sure what to do.