How would I go making a custom key unlocking System?

I would love making a system that works like Pressure’s Radio where you turn the knob.

Instead of turning a knob, however, you would turn a key in order to find a sweet spot in order to open the door. I wouldn’t make the door unlock manually (quick little edit here, but i meant “automatically”, i was tired and didn’t notice my error there!) , but instead whenever the key begins to change a different, brighter color, that’s when players reached the sweet spot.

How would I go making this?

2 Likes

You could rotate a part or a UI object when the player presses A or D and check if the rotation is equal to the sweet spot

i think i have an idea of what you want. so first you have to identify the axis of rotation. i would assume its the z axis. then you would compare the key’s z rotation to the target rotation. you could perhaps subtract them, get the absolute value and divide by 180 if in degrees or divide them by pi if in radians. lets call this number progress. then you would lerp the color of the key ex. key.Color:Lerp(your_color, progress).

local key = path_to_key

local unlockAngle = 45
local progress = 0

local function updateProgress()
   progress = math.abs(key.Orientation.Z - unlockAngle)/180
   key.Color = Color3.fromRGB(255, 0, 0):Lerp(Color3.fromRGB(0, 255, 0), progress)
end

mb, I got confused with your comments and the code.

Going off of what @96por is saying (About it being similar to how the Pressure radio changes colors)
I believe it would be more something like this.

local key = path_to_key

local keyOriginalColor = key.Color
local keyCorrectColor = Color3.new(0, 1, 0)

local unlockAngle = 45
local progress = 0

local function updateProgress()
   progress = math.abs(key.Orientation.Z - unlockAngle)/180
    if progress == 1 then
       key.Color = key.Color:Lerp(keyCorrectColor, 0.25)
    else
       key.Color = key.Color:Lerp(keyOriginalColor, 0.25)
    end
end

(I don’t remember clearly if the Pressure radio interpolates the color, so it may not even be required)

1 Like

erm what? why r u lerping in an if statement? just make keycorrectcolor 0, 0.25, 0

If you look at Pressure videos on the Hunt Event (What they’re referencing to) it only changes color if it’s in the right spot, not as it gets closer to the right spot

1 Like

[1]: Create a Key UI element: Design a key UI element that players can interact with. You can use a Frame or a TextLabel with a Button parented to it. This will serve as the key that players will turn.

[2]: Create a Key Color UI element: Design a UI element that will display the color of the key. You can use a TextLabel or a Frame with a TextLabel child. This will show the color of the key as players turn it.

[3]: Create a Door UI element: Design a door UI element that will serve as the door that players need to unlock. You can use a Frame or a ScreenGui to create a doorlike UI element.

[4]: implement script:

– Get the UI elements
local key = script.Parent
local keyColor = key:WaitForChild(“KeyColor”)
local door = game.Workspace.Door

– Get the TweenService
local TweenService = game:GetService(“TweenService”)

– Function to change the key color
local function changeKeyColor(color)
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local tween = TweenService:Create(keyColor, tweenInfo, {TextColor3 = color})
tween:Play()
end

– Function to check if the key is in the sweet spot
local function checkSweetSpot()
– Define the sweet spot color
local sweetSpotColor = Color3.new(1, 1, 1)

-- Check if the key color is close enough to the sweet spot color
if keyColor.TextColor3.L - sweetSpotColor.L <= 0.1 then
    return true
end
return false

end

– Connect to UserInputService
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
– Change the key color when the player clicks the key
changeKeyColor(Color3.new(math.random(), math.random(), math.random()))
end
end)

– Connect to UserInputService to check for sweet spot
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
– Check if the key is in the sweet spot
if checkSweetSpot() then
– Unlock the door
door.Locked = false
end
end
end)

Let me know if this helped you or not ill try to give more support if not. (originally responded to the wrong person…)

1 Like

just formatted the code

– Get the UI elements
local key = script.Parent
local keyColor = key:WaitForChild(“KeyColor”)
local door = game.Workspace.Door

– Get the TweenService
local TweenService = game:GetService(“TweenService”)

– Function to change the key color
local function changeKeyColor(color)
   local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
   local tween = TweenService:Create(keyColor, tweenInfo, {TextColor3 = color})
   tween:Play()
end

– Function to check if the key is in the sweet spot
local function checkSweetSpot()
   – Define the sweet spot color
   local sweetSpotColor = Color3.new(1, 1, 1)

   -- Check if the key color is close enough to the sweet spot color
   if keyColor.TextColor3.L - sweetSpotColor.L <= 0.1 then
      return true
   end
   return false
end

– Connect to UserInputService
UserInputService.InputBegan:Connect(function(input)
   if input.UserInputType == Enum.UserInputType.MouseButton1 then
      – Change the key color when the player clicks the key
      changeKeyColor(Color3.new(math.random(), math.random(), math.random()))
   end
end)

– Connect to UserInputService to check for sweet spot
UserInputService.InputChanged:Connect(function(input)
   if input.UserInputType == Enum.UserInputType.MouseButton1 then
      – Check if the key is in the sweet spot
      if checkSweetSpot() then
         – Unlock the door
         door.Locked = false
      end
   end
end)
1 Like

Did mine have an error? @ABizarre_Dummy

just formatted it like i said. you can put the code in triple backticks then i can delete that post

1 Like

what do you mean by L? is that an instance?

also why are you randomizing the colour? im not entirely sure how the pressure thing works, but idk if this will make it work as intended

also this is a minor problem but i think you should use input ended instead of changed

im a bit confused. what is keyColor? why are you changing the text colour of it? is it a label perhaps?

1 Like

Oh okay thank you, for the feedback!

updated the feed back and i have a few questions. i trust in that your solution is more accurate than mine cuz idk the pressure thing but just some clarification would be nice

1 Like

The OP said this: “Instead of turning a knob, however, you would turn a key in order to find a sweet spot in order to open the door. I wouldn’t make the door unlock manually, but instead whenever the key begins to change a different, brighter color, thats when players reached the sweet spot.”

To clarify your question about key color which is why the color changes

1 Like

wait but the key rotation doesnt change?

it should tho. @96por could you please clarify on exactly how you want this. but if im being honest i think all of us have provided sufficient solutions.

1 Like

@96por can you respond to any of the solutions.

Sorry I’ve been at school, I’ll try to test all the solutions each one of you gave!

1 Like

You hold A or D in order to turn the key, when the script detects the keys rotation has reached the “Sweet Spot” it will slightly brighten the key and tell the function that the door can be opened.

Okay, thanks for the update! Sorry for rushing you just felt like you were kinda ignoring but I understand the situation.