Proximity Prompt Script not working

Hey, so I am working on a horror game for someone, and I am trying to make a door with a proximity prompt that when activated, it enables a GUI that says the Door is locked, but the script does not work.

Here is the script:

local Proximity = script.Parent
Proximity.Triggered:Connect(function(player)
	game.StarterGui.DoorLocked.TextLabel.Visible = true
	wait(2)
	game.StarterGui.DoorLocked.TextLabel.Visible = false
end)

I used the same structure of script for another door, that teleports you instead of saying its locked, and it worked, but this one does not? I dont know why, I used the same structure for both scripts, I am baffled and confused.

2 Likes

Use Player.PlayerGui, StarterGui only handles replication of Objects to the Player’s PlayerGui

local Proximity = script.Parent
Proximity.Triggered:Connect(function(player)
	local playerGui = player.PlayerGui
	playerGui.DoorLocked.TextLabel.Visible = true
	wait(2)
	playerGui.DoorLocked.TextLabel.Visible = false
end)
3 Likes

I tried it, and it still does not work. Weird.

Where is this script located and what type of script is it?

The script is located inside the proximity prompt, and it is a local script. I have tried it on a regular script as well, no results.

Change it to a regular script, localscripts do not work as a descendant of workspace

1 Like

That has to be the problem, tested his script in a regular script and it fired corrrectly.

1 Like

Surprised y’all haven’t seen this yet

The only other instance that I could see is that you haven’t assigned your GuiObjects correctly if the script didn’t work if it didn’t work on a Server Script

The thing is @OP didn’t really specify if the regular script didn’t work with his old code or my code. If it’s my code then it’s probably a gui issue, although it would’ve errored for him if it was, so best I can assume is that he hasn’t tried my script in a regular script or gui name issue

1 Like

It doesnt work with your updated code as well.

Are you getting any errors when trying to run it or completely errorless?

¯_(ツ)_/¯

Well now we know what to say in a nutshell then:

  • Server Script, not LocalScript

  • Use @EmbatTheHybrid’s code, if the changes aren’t replicated then it’s a GUI Issue

It runs with no errors whatsoever

Okay may we see where your script is located i nthe explorer? The only thing I can think off is that the name is incorrect or you’re still using a localscript

1 Like

I’m blind :flushed:
Instead of using

game.StarterGui.DoorLocked.TextLabel.Visible = true

Use

local Proximity = script.Parent
local Player = game.Players.LocalPlayer
local gui = Player.PlayerGui
local UI1 = gui:FindFirstChild("DoorLocked")
Proximity.Triggered:Connect(function(player)
	UI1.Enabled = true
	wait(2)
	UI1.Enabled = false
end)
1 Like

I swear if you need to literally just make 1-3 changes in order to fix this script:

local Proximity = script.Parent
print("Script online")

Proximity.Triggered:Connect(function(player)
    print("Triggered")
	local playerGui = player.PlayerGui
	playerGui.DoorLocked.TextLabel.Visible = true
	wait(2)
	playerGui.DoorLocked.TextLabel.Visible = false
    print("Untriggered")
end)

It could also be because that you haven’t drafted the Script recently?

1 Like

Drawing (26) its basically just inside a part

1 Like

Convert it to a regular script and try again, localscripts will not execute if they’re not a descendant of something related to a Player instance

1 Like

It’s literally still a LocalScript

Just change it to a Server Script and it should work…?

1 Like

I did it again to be sure, and still did not yield any results.

1 Like