I think the error is somewhere in the first function, because the screenGui.Enabled = false line at the start seems to be working just fine.
The ScreenGui is only relevant while youâre not playing the game. When you start the game, the GUI you see is located inside of the PlayerGui. So yes, the ScreenGui is cloned to the PlayerGui when the character loads.
Maybe trying print some more lines that you think itâs bug? So I will know more about that
Yeah, Iâve tried putting a print line in the first function and it didnât output, so its probably something with this line
if humanoid and humanoid:GetState() == Enum.HumanoidStateType.Seated and hasBeenHeld == false then
You should try printing each variable then.
Print the following before the âifâ statement.
Print(humanoid, humanoid:GetState(), hasBeenHeld)
Thatâs weird, I didnât even get a single output or error. Hereâs what the output comes out with, most if not all of the errors are irrelavent however and have no impact on the game.
Maybe itâs the infinite yield?
I have an idea
Just enable âResetOnSpawnâ instead of
-- Function to check if the player dies and reset the flag
local function onDeath()
hasBeenHeld = false
screenGui.Enabled = false
end
Youâre right, I could remove the screenGui.Enabled, but thereâs no way to tick ResetOnSpawn for the variable.
Why donât you wanna tick the ResetOnSpawn?
Because the variable cannot be found through the explorer, and there is no âResetOnSpawnâ option for it.
Sorry to jump in during conversation, but after going through this post, I believe you want the following
- A gui appears the moment you equip a specified tool for the player only
- This gui dissapears on death/leaving
Am I missing anything?
If not:
The past replies are correct in that you need to reference the Gui through the player and not StarterGui
My solution would just to listen to the âEquippedâ event on the tool, and with a debounce you just enable the Gui from there
And âResetOnSpawnâ should be a property of the ScreenGui
(this object)
Example code of what Im talking about
Tool = *reference tool here*
Gui = *reference gui here
GuiDebounce = false
Tool.Equipped:Connect(function()
if GuiDebounce == false then
GuiDebounce = true
Gui.Enabled = true
end
end)
And the ResetOnSpawn should handle resetting the Gui, assuming you lose this tool on death
No, youâre not missing anything, thatâs exactly what Iâm looking for. To my knowledge, the gui is already referenced through the player, and itâs something wrong with the function thatâs preventing it from appearing. Iâm pretty new to scripting and Iâve been piecing forums together to make this so Iâm not entirely sure what the if statement is saying. Also, what I was saying in my previous post was that I have to keep the onDeath() function because the local variable hasBeenHeld wonât reset without it, and because thereâs no property for a variable to reset on death without the function it would stay true.
Oops, I completely missed this, Iâll try it right now.
Wow, it worked! Thank you so much bro, you have no idea how much you helped me. Iâll try to see if I can code the onDeath function which shouldnât be too hard, but do you think you could help me out if Iâm still having issues?
First of all, glad I can help
Second of all, I just want to make sure with this question
On the ScreenGui, there is not a property named ResetOnSpawn?
(Shown below here)
No no no, what I meant was in the old script I had a local variable that needed to be reset on death. The screengui did not have to be there so I later removed it, but the local variable still had to be reset and thereâs no ResetOnDeath property for that.
So I was able to create a death function, is this efficient or is there a better way to do this?
player.Died:Connect(function()
GuiDebounce = false
end)
Ah, sorry for the misunderstanding.
About this onDeath function, it shouldnt be too complicated
First we need to find the Humanoid of the player, as that is what essentially âdiesâ in this scenario
(assuming this is in a local script)
Players = game:GetService("Players")
player = Players.LocalPlayer
Character = player.Character or player.CharacterAdded:Wait() -- this is becauce there are times the character may not be loaded yet when the script makes this variable
Humanoid = Character:FindFirstChild("Humanoid") -- Humanoid can be a little tricky to get sometimes with simple period notation, so FindFirstChild helps with that
-- Next, we simply get the event when the Humanoid dies
Humanoid.Died:Connect(--your function here)
I hope this solution works!