Display Text When Player Is Holding Tool

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)
image

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)
image

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!