Not sure what kind of script to use

I have this script

local gui = game.Players.LocalPlayer.PlayerGui.ScreenGuiNote
local debounce = false

game.Workspace.myClickDetectorEventNote.OnServerEvent:Connect(function()
	if not debounce then
		debounce = true
		gui.Enabled = true
		wait(5)
		gui.Enabled = false
		debounce = false
	end
end)

And it won’t work. I got this error
Workspace.myClickDetectorEventNote.notescript23:1: attempt to index field 'LocalPlayer' (a nil value)

I’m pretty sure its because its a normal script in the workspace, but I’m not sure where to put the script otherwise, and if it needs to be a local script, well I’m still not sure where I would put it. Someone said it should be a server script but I’m not sure where to get a server script from or where I would put it, so if someone could help me please?

1 Like

This script won’t work no matter what type of script it is. It has LocalPlayer, which only exists in a local script, and OnServerEvent, which will only fire on the server.

2 Likes

So what should I do instead? Or would I just have to make multiple scripts?

1 Like

You shouldn’t be handling UI in a server script anyway. There’s no reason for the OnServerEvent stuff; if you need to communicate with another LocalScript you can use a BindableEvent.

2 Likes

How do I use the event? Would I write the local script and then reference the event with the normal script inside?

1 Like

What are you trying to do? This script right now listens for a RemoteEvent to be fired by another local script. Is there a reason you can’t just disable and reenable the UI in that script?

2 Likes

In order for a LocalScript to work, it must be in the player.

To achieve this, I place the GUI in StarterGui and put the LocalScript inside of it. When the game starts, the script will be under your player and it will work.

This is what the script should look like

local gui = game.Players.LocalPlayer.PlayerGui.ScreenGuiNote
local debounce = false

workspace.Part.ClickDetector.MouseClick:Connect(function()
	if not debounce then
		debounce = true
		gui.Enabled = true
		wait(5)
		gui.Enabled = false
		debounce = false
	end
end)

If this helps please make sure you mark it as a solution! :slight_smile:

1 Like

I have this part, and when clicked on a screengui is supposed to get enabled, and wait 5 seconds, and then disappear. And I’m not sure how to disable and reenable the UI in a local script when the part is clicked.

Connect isn’t a valid member of clickdetector

Sorry! My bad, I was in a rush.

Make it

workspace.Part.ClickDetector.MouseButton1Click:Connect(function()
1 Like

MouseButton1Click is not a valid member of ClickDetector

try MouseClick

:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

1 Like