I need help, My menu gui will stop working whenever another person joins the game, which is very annoying, how would I fix this? I’m not sure how.
So here’s the scripts:
The localscript in the menu gui, which is in replicated storage:
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 UIS = game:GetService("UserInputService")
local UI = script.Parent
local KeyButton = UI:WaitForChild('KeyFrame')
local FadeFrame = UI:WaitForChild('FadeFrame')
local SpawnText = FadeFrame:WaitForChild('Spawn')
local AnyKey = KeyButton:WaitForChild('PressKeyLabel')
local tweenService = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(
0.6,
Enum.EasingStyle.Quart,
Enum.EasingDirection.Out,
0,
false,
0
)
local tweenInfo2 = TweenInfo.new(
0.6,
Enum.EasingStyle.Quart,
Enum.EasingDirection.Out,
0,
false,
0
)
local newColor = Color3.fromRGB(216, 86, 86)
local oldColor = Color3.fromRGB(255, 255, 255)
local tween = tweenService:Create(FadeFrame, tweenInfo, {BackgroundTransparency = 0})
local tweenText = tweenService:Create(SpawnText, tweenInfo, {TextTransparency = 0})
local Presstween = tweenService:Create(AnyKey, tweenInfo, {TextTransparency = 0})
local PressStroketween = tweenService:Create(AnyKey, tweenInfo, {TextStrokeTransparency = 0})
local tween2 = tweenService:Create(FadeFrame, tweenInfo2, {BackgroundTransparency = 1})
local tweenText2 = tweenService:Create(SpawnText, tweenInfo2, {TextTransparency = 1})
local ColorTween = tweenService:Create(AnyKey, tweenInfo, {TextColor3 = newColor})
local ColorTween2 = tweenService:Create(AnyKey, tweenInfo, {TextColor3 = oldColor})
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
local inMenuVal = Player:WaitForChild("InMenu")
local connections = {} -- this is for stopping the 'Heartbeat' function from running after character has reloaded
local function cameraFunc() -- this function should be called when player goes back into menu (if that is an option)
if connections.playerInMenu ~= nil then -- prevent the function from running more than once
return
end
connections.playerInMenu = game:GetService("RunService").Heartbeat:Connect(function()
if not inMenuVal.Value then -- when player is not in menu
UI.Enabled = false -- I'm going to assume 'UI' is your ScreenGui
if connections.playerInMenu then
connections.playerInMenu:Disconnect() -- disconnects the function
connections.playerInMenu = nil
end
end
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 = 75
end)
end
Camera.CFrame = workspace.CameraPart.CFrame
inMenuVal.Changed:Connect(function()
if inMenuVal.Value then
cameraFunc() -- run camera function when player goes into menu again
else
Camera.CameraSubject = Player.Character:WaitForChild("Humanoid")
end
end)
cameraFunc()
wait(3.5)
Presstween:Play()
PressStroketween:Play()
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard and inMenuVal.Value then
KeyButton.Ding:Play()
AnyKey.Text = "PLEASE WAIT..."
ColorTween:Play()
wait(2.5)
tween:Play()
tweenText:Play()
task.wait(3.5)
ColorTween2:Play()
tween2:Play()
tweenText2:Play()
game.Players.CharacterAutoLoads = true
task.wait()
game.ReplicatedStorage.LoadChar:FireServer()
Camera.CameraType = Enum.CameraType.Custom
end
end)
And the script in serverscriptservice:
game.Players.PlayerAdded:Connect(function(Plr)
game.ReplicatedStorage.Spawn.Parent = Plr:WaitForChild("PlayerGui")
end)
local characterLoader = game.ReplicatedStorage:WaitForChild("LoadChar")
local function loadCharacter(client)
if client then
local InMenuValue = client:FindFirstChild("InMenu")
if InMenuValue and InMenuValue.Value then
print(client.Name .. " had no character loaded, loading their character now!")
client:LoadCharacter()
InMenuValue.Value = false -- this will execute once the character has loaded
end
end
end
characterLoader.OnServerEvent:Connect(loadCharacter)
Not sure what to do, so any ideas?