Does anyone know why this won't work?

Does anyone know why this won’t work?

local gui = game.StarterGui.DialogueUi.TextLabel
local debounce = true

local function doSomething (otherPart)
	if debounce and otherPart:FindFirstChildWhichIsA("Humanoid")  then
		debounce = false 
		gui.Enabled = true
		wait(2)
		debounce = true
		
	end
end

gui.Touched:Connect(doSomething)
2 Likes

What exactly is it you are trying to achieve?

When the player steps on a block, a text label GUI will be enabled

2 Likes

make that

local function doSomething(otherPart) then try

3 Likes

Instead of Gui.Touched use Block.Touched. By block I mean your part

3 Likes

Also your final line, you are saying when GUI.Touched? Do you mean [YourPart].Touched

3 Likes

No event Touched for a GUI object.

If you want hover effects, use MouseEnter and MouseLeave.

edit: the person above beat me to it (yes you should use Part.Touched)

I changed it to this,

local gui = game.StarterGui.DialogueUI.TextLabel
local part = script.parent
local debounce = true

local function doSomething(otherPart)
	if debounce and otherPart:FindFirstChildWhichIsA("Humanoid")  then
		debounce = false 
		gui.Visible = true
		wait(2)
		debounce = true
		
	end
end

part.Touched:Connect(doSomething)

But it still won’t function

Im not much of a scripter yet i cna do basic stuff, but your never getting the player that hit it are you?

A couple of things:

  • Touched gives the touched part as a parameter, not the character.
  • You’re editing the things in StarterGui, which do not replicate to PlayerGui until PlayerGui is refreshed (re-replicated, e.g. on join)

Try this:

local players = game:GetService("Players")

local part = script.Parent
local debounce = true

local function doSomething(otherPart)
    if not debounce then return nil end
    local player = players:GetPlayerFromCharacter(otherPart.Parent)
    if player then
        player.PlayerGui.DialogueUi.TextLabel.Visible = true
        debounce = false
        task.wait(2)
        debounce = true
    end
end

part.Touched:Connect(doSomething)

I’d recommend doing all GUI things client-side, using a RemoteEvent.

You’re trying to enable a TextLabel?
If you want to enable the Gui itself just write this instead:
local gui = game.StarterGui.DialogueUI

This should fix it.

i don’t understand? (needmorecharacters)

I made a mistake with the original code, I want to make a text label visible - but it still won’t function

Does your script output any errors?

Does not output any errors in the output box

Try the code I sent above. If that doesn’t work, I need to know a couple more bits:

  • Is this a Script or a LocalScript?
  • Where is it in the Explorer?

It’s a server script, but its a one player game so it doesn’t matter all that much I suppose.

The script is located as a child of the part the player touches to make the text label visible

It must be a LocalScript inside of either StarterGui or another service the client can access

No, it doesn’t. The server can access the player’s PlayerGui, which is everything you can see on your screen. I pointed out issues in my other post.

Yeah, it is recommended to do GUI stuff client-side, but it’s not impossible to do it on the server.

You’re right, I forgot about that.