ive got a running script that changes the player’s FOV slightly. whenever the main menu is active, i want to make it so the running script is disabled whenever the menu is active. the script works, but it only works when the player joins; if they die and go back to the main menu, the running script doesnt disable again. how do i make it disable whenever the menu is active?
main menu script:
--code mostly taken from: https://www.youtube.com/watch?v=ecyKTDFOl5g&ab_channel=DevFlare, changes made by me
local CurrentCamera = workspace.CurrentCamera --get local players camera
local CameraPart = workspace:WaitForChild("menucamerapart") --get the camera part
local PlayButton = script.Parent.Frame.PlayButton --get the actual play button on the frame
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") --get local player's humanoid
local Frame = script.Parent.Frame --get main menu frame
local RunScript = game.StarterPlayer.StarterCharacterScripts.RunScript
local spawnpads = workspace.spawnpads:GetChildren() --get spawn locations
--wait(0.001) --no clue why this is here tbh
CurrentCamera.CameraType = Enum.CameraType.Scriptable --allow camera to be controlled by scripts
CurrentCamera.CFrame = CameraPart.CFrame --set camera's cframe to the cframe of the camera part
Frame.Visible = true --make frame visible (just easy to work on studio with this, dont gotta hide ui n stuff)
Humanoid.WalkSpeed = 0 --player cant move when main menu is on
Humanoid.JumpPower = 0 --player cant jump when main menu is on
RunScript.Enabled = false
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) --hide the backpack from player
game:GetService("StarterGui"):SetCore("ResetButtonCallback", false) --disable resetting in main menu
function Play()
CurrentCamera.CameraType = Enum.CameraType.Custom --set camera back to default settings
Humanoid.WalkSpeed = 24 --let player move
Humanoid.JumpPower = 50 --let player jump
RunScript.Enabled = true
local selectedspawn = spawnpads[math.random(1, #spawnpads)] --select random spawn from spawnpads folder
Humanoid.Parent:MoveTo(selectedspawn.Position) --tp player on the map from spawn box
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true) --show the backpack again
game:GetService("StarterGui"):SetCore("ResetButtonCallback", true) --allow resetting
script.Parent:Destroy() --remove the main menu
end
PlayButton.MouseButton1Click:Connect(Play) --run it
they are destroyed, but whenever a player dies the menu sort of just appears again, im not really sure why tbh since i got parts of the code from a tutorial video
function Play()
CurrentCamera.CameraType = Enum.CameraType.Custom --set camera back to default settings
Humanoid.WalkSpeed = 24 --let player move
Humanoid.JumpPower = 50 --let player jump
RunScript.Enabled = true
local selectedspawn = spawnpads[math.random(1, #spawnpads)] --select random spawn from spawnpads folder
Humanoid.Parent:MoveTo(selectedspawn.Position) --tp player on the map from spawn box
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true) --show the backpack again
game:GetService("StarterGui"):SetCore("ResetButtonCallback", true) --allow resetting
script.Parent:Destroy() --remove the main menu
end
humanoid.Died:Connect(function()
RunScript.Enabled = false
end)
PlayButton.MouseButton1Click:Connect(Play) --run it
also another thing i just found out is that it turns out the thing i have to disable the script upon joining doesnt even work; i thought it did because i didnt click on the game window first before clicking play
Rather than destroying the main menu gui u can just set its visible property to false. then in your sprinting script you should check if the menu gui is visible, if it is end the function
i figured out how to get the local player’s main menu frame and the print statement works as it should (it actually prints “visible” when the menu is on now)
how do i make it so the running script can only work when the frame isnt visible? do i need to put the UIS functions for it in a huge while loop + if statement or something?
same but put it in a normal non-local script and make it inside startercharacterscript
local Character = script.Parent
local Humanoid = script.Parent:WaitForChild("Humanoid")
local RunScript = game.StarterPlayer.StarterCharacterScripts.RunScript
Humanoid.Died:Connect(function()
RunScript.Enabled = false
end)