Hm… I will give it a try and test it later
ok ok so lets go over this.
- the menu gui is defaulted to reset on spawn.
- the server script disabled all of there scripts (which start off as enabled).
- when the player presses play, you make the menu gui invisible and set reset on spawn to false. you also send a remote event to the server script to enable all of the character’s scripts.
- this concludes the proccess, now the menu will never show again and the character scripts will always be enabled by default
I put a Debris service on the menu though. I’m not sure if it will work? I put it there to delete useless assets like when the menu isn’t needed anymore after the player presses play.
debris service is used to delete instances after a certain amount of time. why would you need it for the menu?
I want to clean up useless assets so they don’t take up space on the game. When the menu is not needed anymore, it’ll be cleaned up
Without the Debris affecting the UI
player.CharacterAdded:Connect(function(character)
NoCollision(character)
ForceField(character)
Health_Bar(player, character)
task.wait() -- Make sure the UI has time to load
local Loaded = not Path.To.MenuGui.ResetOnSpawn
if not Loaded then
-- Disable the scripts
repeat
task.wait()
Loaded = not Path.To.MenuGui.ResetOnSpawn
until Loaded
end
-- Enable the scripts
end)
With Debris affecting the UI
player.CharacterAdded:Connect(function(character)
NoCollision(character)
ForceField(character)
Health_Bar(player, character)
task.wait() -- Make sure the UI has time to load
local Loaded = player.PlayerGui:FindFirstChild("MenuName") == nil
if not Loaded then
-- Disable the scripts
repeat
task.wait()
Loaded = not player.PlayerGui:FindFirstChild("MenuName") == nil
until Loaded
end
-- Enable the scripts
end)
(Note, the Debris deletion check will be delayed by how long it takes to delete)
The script with Debris should work as long as it stays deleted and was deleted from a ServerScript
Yeah it was deleted from a server script. I will give it a try later though due to homework right now. I will let you know if it works or not!
so why use debris? just destroy it when the player presses play or after they r done with it. in that case you dont need to worry about changing the reset on spawn property
local BadgeService = game:GetService("BadgeService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUIs = ReplicatedStorage:WaitForChild("GUIs")
local HealthGui = GUIs:WaitForChild("HealthGui")
local PlayerUserText = HealthGui:WaitForChild("PlayerUsername")
local Pre_Alpha_Tester_Text = GUIs:WaitForChild("Pre-Alpha-Tester-Text")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Enable_Blur_Remote = Remotes:WaitForChild("Enable_Blur")
local BadgeID = 349466981534156
local function ForceField(character)
local ForceField = Instance.new("ForceField")
ForceField.Visible = false
ForceField.Parent = character
end
local function Health_Bar(player, character)
local Head = character:WaitForChild("Head")
local HealthGui_Clone = HealthGui:Clone()
local PlayerUser = HealthGui_Clone:WaitForChild("PlayerUsername")
HealthGui_Clone.Parent = Head
PlayerUser = player.Name
if not BadgeService:UserHasBadgeAsync(player.UserId, BadgeID) then return end
Pre_Alpha_Tester_Text:Clone().Parent = HealthGui_Clone
end
local function NoCollision(character)
for i, v in character:GetDescendants() do
if v:IsA("BasePart") then
v.CollisionGroup = "Players"
else
continue
end
end
end
local function Dash_Key_SetUp(player)
local DashKey = Instance.new("StringValue")
DashKey.Name = "Dash_Key"
DashKey.Value = "Q"
DashKey.Parent = player
end
game.Players.PlayerAdded:Connect(function(player)
Dash_Key_SetUp(player)
player.CharacterAdded:Connect(function(character)
NoCollision(character)
ForceField(character)
Health_Bar(player, character)
task.wait()
local Loaded = not player.PlayerGui:FindFirstChild("Menu").ResetOnSpawn
if not Loaded then
for i, v in character:GetDescendants() do
if not v:IsA("Script") or not v:IsA("LocalScript") then continue end
v.Enabled = false
end
repeat
if Loaded then break end
task.wait(0.1)
print("Not loaded")
until Loaded
for i, v in character:GetDescendants() do
if not v:IsA("Script") or not v:IsA("LocalScript") then continue end
v.Enabled = true
end
end
end)
end)
Wow! It works but there’s a drawback. It only works when reset on spawn is enabled. I etsted this and when the player resets, it breaks the menu.
Sorry, I assumed you only wanted the menu to appear once and not after the player dies as well.
If you want the menu to appear on screen after the player respawns, you could try replacing ResetOnSpawn with simply checking when the button is pressed.
local Menu = player.PlayerGui:WaitForChild("Menu", 5)
if Menu ~= nil then -- Make sure the UI exists
--Disable the character scripts
for i, v in character:GetDescendants() do
if not v:IsA("Script") or not v:IsA("LocalScript") then continue end
v.Enabled = false
end
--Check for whenever the play button is pressed
local PlayerLeaveConnect
local ButtonConnect
ButtonConnect = Menu.Path.To.Button.MouseButton1Down:Connect(function()
--Finally, enable the character scripts when the player presses the play button.
for i, v in character:GetDescendants() do
if not v:IsA("Script") or not v:IsA("LocalScript") then continue end
v.Enabled = true
end
--Prevent memory leaks
ButtonConnect:Disconnect()
ButtonConnect = nil
if PlayerLeaveConnect ~= nil then
PlayerLeaveConnect:Disconnect()
PlayerLeaveConnect = nil
end
end)
PlayerLeaveConnect = player.Destroying:Connect(function()
--Prevent memory leaks
if ButtonConnect ~= nil then
ButtonConnect:Disconnect()
ButtonConnect = nil
end
PlayerLeaveConnect:Disconnect()
PlayerLeaveConnect = nil
end)
else
--warn("Missing UI!")
end
Remember to change “Menu.Path.To.Button” to be correctly where your button is in the menu
And then remove the script connecting the play button to turning the UI’s ResetOnSpawn off. This way, the UI will still show because ResetOnSpawn is true, but we’ll be able to tell if the play button was pressed.
Would’ve posted this kind of solution a while ago but I was tired when writing my original solution.
This should work.
Is this a local script or a server script? There’s two scripts. A server script for setting up the player when they join (including disabling character scripts) and a local script for when the button is pressed
This is in the script that disables the character scripts, you can replace the “local Loaded = not…” section with this.
Thank you, it works now! Yippie
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.