Does anyone know why this won't work?

So if I make a local script, make it a child of the ‘TextLabel’ in startedGUI

local BrickTouch = game.Workspace.BrickTouch
local debounce = true

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

BrickTouch.Touched:Connect(doSomething)

I guess that could work, but you get the issues with waiting on replication. Try this code, which is a Script as a child to the Part:

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)
2 Likes

Instead of getting it from the starterGui, start your script like this:

local player = game:GetService("Players").LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")

local gui = PlayerGui:WaitForChild("DialogueUI")

Excellent!!! It works now :smiley: tysm. Thanks everyone for their help

2 Likes

Glad it works! Make sure to mark this topic as solved so it can close and other people know it’s solved.

let me just open a forum on how to mark a topic as solved. jk lol thx for ur help

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.