Trouble w scripting

So I’m not really good at scripting, but I have trouble with one thing. I wanted to make a script that doesn’t work. It’s supposed to show a message after touching a part, but no matter what I do, it never works.
local Player = game.Players.LocalPlayer

local function OnTouch()

Player.PlayerGui:FindFirstChild("Interactive").Enabled = true 

wait(5)

Player.PlayerGui:FindFirstChild("Interactive").Enabled = false

end

game.Workspace:FindFirstChild(“touchpart”).Touched:Connect(OnTouch)

The first 2 is the name of my gui and the last one is the name of the part. I watched a few tutorials yet none of them worked. It’s kinda confusing how there’s not a single mention of the text label. And yes, this script is both in the part and in gui related to it.

2 Likes

One potential mistake I’m seeing is that you aren’t checking whether the object touching “touchpart” is a child of the character. Another problem might be that you are trying to run a local script in the workspace. You can only run local scripts in client based container services, like StarterPlayer or StarterGui.

Let’s start with the fact that it is not advisable to write such things in a local script; they are intended for the server. The cause of the breakdown in your case is FindFirstChild; it does not wait for the part to load, but immediately tries to find it and produces nil if it does not find anything. Use waitForChild instead, here is a code example in your case.

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer

local debounce = false

workspace:WaitForChild("touchpart").Touched:Connect(function(p)
	if not debounce and p.Parent:FindFirstChild("Humanoid") then
		local player = players:GetPlayerFromCharacter(p.Parent)
		
		if player.Name == localPlayer.Name then
			debounce = true
			
			player.PlayerGui.Interactive.Enabled = true
			
			task.wait(5)
			
			player.PlayerGui.Interactive.Enabled = false
			
			task.wait(.5)
			
			debounce = false
		end
	end
end)

Hello, I’ve faced this issue, the thing is some reason ScreenGUI doesn’t enable back or disables after it’s enabling value has been changed (Script-Wise), idk why but I have also had this issue to fix this just do this:

  • Create a frame Size = [1, 0], [1, 0]
  • Parent your textLabel or the thing you want to display under it
  • Make your frame’s visible property to false, making all parented childs under it to also be not visible
  • Now change the function to do the following code below to
local ScreenGUI = Player.PlayerGui:FindFirstChild("Interactive")
ScreenGUI:FindFirstChild(FRAME_NAME_HERE).Visible = true
wait(5)
ScreenGUI:FindFirstChild(FRAME_NAME_HERE).Visible = false

Please inform me if this solved your issue. By the way make sure you :WaitForChild for the part.

I used it as a normal script and it didn’t work either, but lemme try again

Thanks for trying, but for some reason it doesn’t work
I guess I’ll just use a free model and try my best to customize it

Well, I tried it out but it didn’t work, still thanks tho

So the problem is something else, since the script works for me, tell me,

  1. is this a local script?
  2. are there any errors in the console?
  3. interactive and touchpart always exist or only at certain times?
  1. I checked both local scripts and normal ones
  2. The console doesn’t show any of them
  3. they exist all the time
    also mb for such late responses but I’m not really active in here

Make sure that when you post a script. Highlight the entire script and click on the format script button. It should be above where you write. Because only part of your script is showing formated

Can you show the gui in the explorer?

By the way I see this: game.Workspace:FindFirstChild(“touchpart”).Touched:Connect(OnTouch)
Maybe the function isn’t calling. Maybe put it as instead perhaps?: game.Workspace:FindFirstChild(“touchpart”).Touched:Connect(OnTouch())

Guys, I decided to take a look and I realised I put the gui in a folder named screengui

I’m not sure if that’s what you mean but take a look
Zrzut ekranu (1178)

nevermind, nothing happend anyway

Well, it didn’t help much, nothing happend

Can you show the Interactive expanded.

Zrzut ekranu (1179)
There’s nothing much, I tried a few combinations, like putting textlabel in the part, putting textlabel in localscript and vice versa etc

Is the TextlLable visibility set to true?

I gotta check because I don’t even know, hold on