Add a script inside the ClickDetector, and include the following code in it:
local AllowedPlayers = {39922681, 1} -- Add whoever you want to be able to click the ClickDetector (user id)
script.Parent.MouseClick:Connect(function(Player)
local FoundInTable = false
for _, userid in pairs(AllowedPlayers) do
if Player.UserId == userid and FoundInTable == false then
FoundInTable = true
end
end
if FoundInTable == true then
-- Player found in table, open door
else
-- Player wasn't found in table, show an error gui (preferably, you should fire a remote event to the player, and handle the gui effects on the client)
end
end)
It appears that when I copied the exact same code and put a print function (print(‘Success’) to be exact) underneath the ‘FoundInTable == true’ line, nothing happened. Is is just a Studio problem?
EDIT: I found the problem, it turns out the ‘MouseClick’ isn’t a valid member of Part.
Okay, it all works now! But, if I were to make the error message on the GUI, I just need help with getting the script to display it for a few seconds and then remove it. The rest I’ll be able to handle myself.
Add a RemoteEvent in ReplicatedStorage and call it whatever you like. In this scenario, we’ll just call it ShowGui, you can rename it if you want.
Updated script of the ClickDetector:
local AllowedPlayers = {39922681, 1} -- Add whoever you want to be able to click the ClickDetector (user id)
script.Parent.MouseClick:Connect(function(Player)
local FoundInTable = false
for _, userid in pairs(AllowedPlayers) do
if Player.UserId == userid and FoundInTable == false then
FoundInTable = true
end
end
if FoundInTable == true then
-- Player found in table, open door
else
game.ReplicatedStorage.ShowGui:FireClient(Player)
end
end)
Client script (local script):
game.ReplicatedStorage.ShowGui.OnClientEvent:Connect(function()
script.Parent.Error.Visible = true
wait(3) -- Time to wait before hiding the error text
script.Parent.Error.Visible = false
end)
You can obviously make the gui more cleaner and better by twening it in, adding some special effects with TweenService and stuff like that. You can do that if you like in the client script.
Another approach of showing an error gui, is to copy the gui, parent it to the player’s PlayerGui, and then delete it after a short time (all handled in the server) - but that will give away the option to customize your gui (add special effects, tween it in, etc.)