(Keeping this simple here)
I’ve been looking at this one for a decent while, and I’ll be glad to explain the process behind it (In a different way )
So what the OP wants, is for a Key to open a Door but it’ll be only visible to those who opened the specific door
Now obviously we need our 2 main objects here, the Locked Door & the Key to open the Door with:
There are tons of ways to really do this, but I’ll just stick with my “creative” & “fun” way on how to implement it
Now the first thing what we’d wanna do, since this’ll be to all individual clients, is put our Key inside StarterPack
, cause we want to clone this for all Player Characters that join the game here
Next up, we’ll insert a LocalScript
inside the Tool which will handle the Event that checks for unlocking the door:
local LockedDoor = workspace:WaitForChild("LockDoor")
local Key = script.Parent
local Connection
local function Touched(Hit)
if Hit == LockedDoor then
Connection:Disconnect()
LockedDoor.Transparency = 0.75
LockedDoor.CanCollide = false
end
end
Connection = Key.Handle.Touched:Connect(Touched)
What we’re using is a Touched
Event to detect changes for when the Tool’s Handle is being touched by another object via physics, and we can check the Hit
parameter of the Object that got touched (Or Hit == LockedDoor
)
Next up what we’re using is called a Connection
to check this Touched
Event, this nifty variable can let us set an Event to properly disconnect later inside the function at the right time (Or so that we don’t have to keep it firing over and over and over again, think of it as like a wire that’s connected to something then later cutting it to disconnect said wire)
If our if statement
detects that the Hit
is equal to our LockedDoor
, then we can make our Door invisible to make it so the client (Or Player) can only see it!
Random Content