Admin only script not working

So I made a script for a door to open, it’s supposed to open only when I (or anyone else if I put their name) want it to open,

The problem is that for some reason it just doesn’t detect correctly if it’s me or any other player. It doesn’t give errors or anything, it just opens when ANYONE triggers the proximity prompt.

I’ve searched for solutions for some hours and I couldn’t find anything, I even looked for similar scripts and I didn’t see a difference.

Script (have in mind “proximityprompt” is a variable, and yes it works):

proximityprompt.Triggered:Connect(function(plr)
	if plr.Name == "Epixerty" then
		if debounce == false then
			debounce = true
			openplay:Play()
			mainpart.CanCollide = false
			wait(2)
			closeplay:Play()
			wait(0.5)
			mainpart.CanCollide = true
			debounce = false
		end
	end
end)

Have you tried printing before and after the first if statement to see if that’s working?

Yes, it’s just the same as checking if the door opens or not, it will work if anyone triggers that proximity prompt

Oh and in case you’re wondering the rest of the script is just variables and tweenservice stuff so it doesn’t affect this part

got 3 pieces of advice, not necessarily a solution:

  1. use UserId instead of Name
  2. print the plr and plr.Name after the if statement, and test to see if something is wrong there
  3. if this is in a local script, make sure you didn’t already make a variable called plr (i know it sounds dumb but this happens)

Change the first if statement’s condition and try it again

This should work:

local plrID = -- put the user id here
local locplr = game:GetService("Players").LocalPlayer
debounce = false

proximityprompt.Triggered:Connect(function()
   if debounce == false and locplr.UserId == plrID then
      openplay:Play()
      mainpart.CanCollide = false
      wait(2)
      closeplay:Play()
      wait(0.5)
      mainpart.CanCollide = true
      debounce = false
   end
end)

The segment of the script you provided is fine (and works), you need to share the entire script or at least the parts relevant to this segment, i.e; the definition of the function named “closeplay” and the declaration of the variable “mainpart”.

That defeats the purpose of a ProximityPrompt instance, remember that “game.Players.LocalPlayer” is only defined in local scripts.

thanks, I knew I could use UserId but I was lazy to actually copy my ID so I just used my username. I don’t know why and it could be a roblox issue, but thank you for your help