How can I make it so when you hit a Block with an IntValue a GUI pops up with the Value of the IntValue? By the way, the IntValue changes its value every time you press it.
This is what I have that doesn't work:
script.Parent.Handle.Touched:connect(function(hit) hit.IntValue.Value.Changed:connect(function(value) script.Parent.Parent.Parent.PlayerGui.ScreenGui.TextBox.Text = value end) end)
It looks like you're using a tool, so I'll assume you are. I found three problems with this code.
First being that when your Handle is touched, anything can be touching it, not just the parts with IntValues. So you should check if hit
has an IntValue (named "IntValue") inside of it. We can use FindFirstChild for this!
if hit:FindFirstChild("IntValue") then -- Stuff end
Next, you're trying to use the Changed event incorrectly. The event can only be used on objects that you can view in the Explorer, like Workspace or a Part. Also, the argument given in changed is the name of the property that was changed. We can just set the gui's text value to the IntValue's Value though.
hit.IntValue.Changed:connect(function() -- Change the GUI end)
And finally, when a player equips a tool it is moved to their Character. You seem to be trying to get the player using Parent
s, which doesn't work. Instead you can use the GetPlayerFromCharacter method on the tool's parent.
game.Players:GetPlayerFromCharacter(script.Parent.Parent)
Then just do what you were doing before (mostly), set the text of your GUI.
game.Players:GetPlayerFromCharacter(script.Parent.Parent).PlayerGui.ScreenGui.TextBox.Text = hit.IntValue.Value
This should work fine for you.
script.Parent.Handle.Touched:connect(function(hit) hit.IntValue.Changed:connect(function(value) game:GetService("Players")[script.Parent.Parent.Name].playerGui.ScreenGui.Text = hit.IntValue.Value end) end)