I tried to make a LocalScript which enables the GUI whenever the player respawns, but it doesn’t work. I tried placing it in the respective GUI, I tried to enable the ResetOnSpawn property of the GUI, I even tried placing the script in StarterPlayerScripts and StarterCharacterScripts. I’m still new to coding and all this has given me a headache, I don’t know what to do anymore Here’s the script I tried making so far:
local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function()
player.CharacterAdded:Connect(function()
if player.PlayerGui:FindFirstChild("Loading") == false then
player.PlayerGui.Morph.Enabled = true
end
end)
end)
The GUI is disabled when the player initially joins the game.
I put a loading screen, after some time it enables the morph gui then it destroys itself. Also when you click a button in the morph gui it sets the Enabled property to false. So everytime the player respawns, I tried to make it so that it checks if the loading screen is in the PlayerGui, if it isn’t then it enables the morph gui
Can you confirm if the loading is actually disabled when the character is added? Because the function connected to the CharacterAdded event will only trigger once the character is added, not every time.
I have done a bit of code clean up to make this more easier to understand.
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
if not player.PlayerGui:FindFirstChild("Loading") then
player.PlayerGui:WaitForChild("Morph").Enabled = true
end
end)
Still doesn’t work… I really don’t know what I did wrong
I guess I’ll just make a Gui button that opens/closes the ScreenGui instead. Thanks for the help though
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
if player.PlayerGui:WaitForChild("Loading").Enabled == false then
player.PlayerGui:WaitForChild("Morph").Enabled = true
end
end)
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
if not player.PlayerGui:FindFirstChild("Loading") then
warn(`Player is not in loading`)
player.PlayerGui:WaitForChild("Morph").Enabled = true
else
warn(`Player is still loading.`)
end
end)