Scripting a hide in locker system

Hiya,
I’m trying to make it so when you press the ProximityPrompt on the locker in my game, the player’s camera changes to a part inside the locker and their movement is locked. And when you press the ProximityPrompt again, it takes you back out.
How would I achieve something like this?

Below is my script so far, I just have no idea where to go from here and if this is even the right thing to do

--Variables

local part = script.Parent.LockerCamera
local db = false
local plr = game.Players.LocalPlayer:WaitForChild("Humanoid")

--Function

script.Parent.MetalDoor.Attachment.ProximityPrompt.Triggered:Connect(function(presser)
	if presser ~= game.Players.LocalPlayer then
		plr.
	end
end)
1 Like

Why are you checking if the presser isnt the local player?

1 Like

Is there a better way to do it? The script doesn’t work anyway

1 Like

Well the script is obviously a local script so why are you checking if it isnt the local player, just something I saw that wasn’t quite right

1 Like

I’m totally confused on what to do after I make the function, actually.

1 Like

Okay so you’re going to probably want to have a cameraPart inside of the locker where you want the camera to go when the player enters, so create a non collidable transparent part inside of the locker model and make sure it’s also anchored

1 Like

Alright I’ve added the part inside

1 Like

Put this in a local script. Do note that this only changes the camera subject, it doesnt hide your character from anyone else, you would need some networking for that.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character.Humanoid
local Camera = workspace.CurrentCamera

local Prompt = script.Parent.MetalDoor.Attachment.ProximityPrompt
local LockerCam = workspace.LockerCam

local origSpeed = Humanoid.WalkSpeed
local isHiding = false

local function camToLocker()
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = LockerCam.CFrame
end

Prompt.Triggered:Connect(function(presser)
	if not isHiding then
		Humanoid.WalkSpeed = 0
		camToLocker()
		isHiding = true
	else
		Humanoid.WalkSpeed = origSpeed
		Camera.CameraType = Enum.CameraType.Custom
		isHiding = false
	end
end)

1 Like

Under the locker model, right?

Okay, so I’m not quite sure how other games put the player inside of the locker if it’s like too small because as you know if the locker is too small it’ll be clipping with the locker but one solution is to just anchor them while they are inside of the locker

local part = script.Parent.LockerCamera
local db = false
local plr = game.Players.LocalPlayer:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
--Function

script.Parent.MetalDoor.Attachment.ProximityPrompt.Triggered:Connect(function(presser)
   local lockerCam : Part = 'PATH'

   while (camera.CameraType ~= Enum.CameraType.Scriptable) do
      camera.CameraType = Enum.CameraType.Scriptable
      task.wait()
   end
   -- Set the camera's CFrame to the part's CFrame inside the locker
   camera.CFrame = lockerCam.CFrame
end)
1 Like

I’ve attached an image of the locker model. The script didn’t work anyway, but just incase it was a messup on my side

image

1 Like

I forgot to mention that you have to change the path of ‘LockerCam.’ So if Locker is in workspace, the path would be Workspace.Locker.LockerCamera

The localscript within StarterPlayerScripts. The code SHOULD work. Ill try my best to help you set it up to get it running

1 Like

Ok the code will infinitely yield at line 3 because the player doesn’t have a humanoid, their character does.

I’ll write out some code for you in a sec.

This is what the output is saying. I moved the script to StarterPlayerScripts like you said too

I suggest familiarizing yourself with studio first. Its hard for people to help without you knowing how to navigate around and pinpoint the problems in your code. From the looks of it, ‘MetalDoor’ is not in PlayerScripts (idk why it would be there), but thats why its erroring. Again, I have no context of metaldoor and its function in your script so I cannot help you without additional information.

Will do, thanks so much for your help though

Sure, feel free to send me a message if you have further questions. Roblox also provides a great guide for those like you just starting out.

Roblox Docs

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.