local function SoulTreeGUI()
return player.PlayerGui:WaitForChild("SoulTreeGUI")
end
local function toggleSoulTree()
local SoulTreeGUI = SoulTreeGUI()
local soulTreeCache = player:FindFirstChild("SoulTreeCache")
if not soulTreeCache then
local soulTreeCache = Instance.new("Folder")
soulTreeCache.Name = "SoulTreeCache"
soulTreeCache.Parent = player
end
if SoulTreeGUI.Enabled == false then
SoulTreeGUI.Enabled = true
SoulTreeGUI.SoulTree.Visible = true
elseif SoulTreeGUI.Enabled == true then
SoulTreeGUI.Enabled = false
SoulTreeGUI.SoulTree.Visible = false
end
if #player.SoulTreeCache:GetChildren() ~= 0 then
print("show save and exit pop up thing")
end
end
ContextActionService:BindAction("SoulTreeGUI", function(_, UserInputState)
if UserInputState == Enum.UserInputState.Begin then
toggleSoulTree()
end
end, false, toggleSoulTreeKeyBind)
I am just calling a function to grab the soulTreeGUI to get the soulTreeGUI after setting the players character to a new character. I was wondering if there is a way around this or if it is bad practice/performant to do it this way.
(this is a local script in player scripts, other player scripts work fine atm)
-- Code to show new character ... other code not needed to show
player.Character = newCharacter
newCharacter.Parent = workspace
local soulTreeGUI = player.PlayerGui:WaitForChild("SoulTreeGUI")
local function toggleSoulTree()
local soulTreeCache = player:FindFirstChild("SoulTreeCache")
if not soulTreeCache then
local soulTreeCache = Instance.new("Folder")
soulTreeCache.Name = "SoulTreeCache"
soulTreeCache.Parent = player
end
if soulTreeGUI.Enabled == false then
soulTreeGUI.Enabled = true
soulTreeGUI.SoulTree.Visible = true
print (soulTreeGUI.Enabled, soulTreeGUI.SoulTree.Visible)
elseif soulTreeGUI.Enabled == true then
soulTreeGUI.Enabled = false
soulTreeGUI.SoulTree.Visible = false
end
if #player.SoulTreeCache:GetChildren() ~= 0 then
print("show save and exit pop up thing")
end
end
ContextActionService:BindAction("SoulTreeGUI", function(_, UserInputState)
if UserInputState == Enum.UserInputState.Begin then
toggleSoulTree()
end
end, false, toggleSoulTreeKeyBind)
Also when I put these print statements in before it was printing true for both even though they were false in the explorer on the client
Error logs for previous code
19:16:09.231 true true - Client - SoulTreeUI:20
19:16:11.098 SoulTree is not a valid member of ScreenGui âSoulTreeGUIâ - Client - SoulTreeUI:19
19:16:11.099 Stack Begin - Studio
19:16:11.099 Script âPlayers.PryVexx.PlayerScripts.UIHandlers.SoulTreeUIâ, Line 19 - function toggleSoulTree - Studio - SoulTreeUI:19
19:16:11.099 Script âPlayers.PryVexx.PlayerScripts.UIHandlers.SoulTreeUIâ, Line 31 - Studio - SoulTreeUI:31
19:16:11.099 Stack End - Studio
19:16:11.099 ContextActionService: Unexpected error while invoking callback: SoulTree is not a valid member of ScreenGui âSoulTreeGUIâ - Studio
If itâs disabled on spawn then check off ResetOnSpawn, because resetting (setting again) the character will cause all ScreenGuis with this property enabled to reset. Without deeper understanding in how your code works, Iâve just provided a solution to the simplest scenario