Skip to content
The Chat Archive
qwen3-235b-a22b· Alibaba (Qwen) LMArena Human Preference 140K

ok! so, im making a roblox game that is like five night at freddy's but with a twist,…

  1. User

    ok! so, im making a roblox game that is like five night at freddy's but with a twist, currently, im making a hidding system in my game, but i am having trouble to do that, can you help me figure it out? here is the code that runs in every locker in the game:

    local LockerModule = {}

    LockerModule.HideAndExit = function(plr: Player, locker:Model, PlayerHidding: Player) local door: Model = locker.Door

    local InsideCam: Part = locker.InsideCam
    local InsidePos: Part = locker.InsidePos
    local OutsidePos: Part = locker.OutsidePos
    local Interactable: ProximityPrompt = locker.Interactable.ProximityPrompt
    
    local Hide_Exit_Event: RemoteEvent = locker["Hide/Exit"]
    
    local plrChar = plr.Character
    local plrHrp = plrChar:FindFirstChild("HumanoidRootPart")
    local plrHum = plrChar.Humanoid
    
    if locker:GetAttribute("Avaliable") == true then
    	plrChar:SetAttribute("Hidding", true)
    	locker:SetAttribute("Avaliable", false)
    	Interactable.Enabled = false
    elseif plrChar:GetAttribute("Hidding") == true then
    	if plr ~= PlayerHidding then return error("Player that is requesting to exit isnt the same as the player hidding, Please review the local code or players localScript", 1) end
    	plrChar:SetAttribute("Hidding", false)
    	locker:SetAttribute("Avaliable", true)
    	Interactable.Enabled = true
    end
    

    end

    LockerModule.SetScript = function(locker: Model) print("Set Script to", locker.Name) local Interactable: ProximityPrompt = locker.Interactable.ProximityPrompt local Hide_Exit_Event: RemoteEvent = locker["Hide/Exit"]

    local PlayerHidding = nil
    
    local function InteractableTriggered(Plr: Player)
    	print("Triggered", locker.Name)
    	if Plr == nil then return end
    	
    	local plrChar = Plr.Character
    	local plrHrp = plrChar:FindFirstChild("HumanoidRootPart")
    	local plrHum = plrChar.Humanoid
    	
    	if not plrChar or not plrHrp or not plrHum then return end
    	LockerModule.HideAndExit(Plr, locker, PlayerHidding)
    end
    
    Interactable.Triggered:Connect(InteractableTriggered)
    Hide_Exit_Event.OnServerEvent:Connect(function(plr) LockerModule.HideAndExit(plr, locker, PlayerHidding) end)
    

    end

    return LockerModule

  2. Assistant

    To help you implement a functional hiding system in your Roblox FNAF-inspired game, let's address the key issues in your current code and improve it step-by-step.


    Key Fixes & Improvements

    1. Track Hiding Player Per Locker
      • Use a local variable PlayerHidding in SetScript to track who is hiding in each locker.
    2. Update Player Position & Camera
      • Move the player's character into the locker and adjust the camera.
    3. Validate State Changes
      • Ensure players can only exit the locker they’re hiding in.
    4. Initialize Attributes
      • Ensure lockers start with Avaliable = true.

    Revised Code

    local LockerModule = {}
    
    LockerModule.HideAndExit = function(plr: Player, locker: Model, PlayerHidding: Player)
        local door: Model = locker.Door
        local InsideCam: Part = locker:FindFirstChild("InsideCam")
        local InsidePos: Part = locker:FindFirstChild("InsidePos")
        local OutsidePos: Part = locker:FindFirstChild("OutsidePos")
        local Interactable: ProximityPrompt = locker.Interactable:FindFirstChild("ProximityPrompt")
        local plrChar = plr.Character
        local plrHrp = plrChar and plrChar:FindFirstChild("HumanoidRootPart")
        local plrHum = plrChar and plrChar:FindFirstChild("Humanoid")
    
        if not plrChar or not plrHrp or not plrHum then return end
    
        -- Enter Hiding
        if locker:GetAttribute("Avaliable") == true then
            plrChar:SetAttribute("Hidding", true)
            locker:SetAttribute("Avaliable", false)
            Interactable.Enabled = false
    
            -- Move player into locker
            if InsidePos and plrHrp then
                plrHrp.CFrame = InsidePos.CFrame
            end
    
            -- Set camera to locker cam
            if InsideCam then
                workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
                workspace.CurrentCamera.CFrame = InsideCam.CFrame
            end
    
            PlayerHidding = plr -- Track hiding player
    
        -- Exit Hiding
        elseif plrChar:GetAttribute("Hidding") == true then
            if plr ~= PlayerHidding then return warn("Player is not hiding in this locker") end
    
            plrChar:SetAttribute("Hidding", false)
            locker:SetAttribute("Avaliable", true)
            Interactable.Enabled = true
    
            -- Move player out of locker
            if OutsidePos and plrHrp then
                plrHrp.CFrame = OutsidePos.CFrame
            end
    
            -- Reset camera
            workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
            PlayerHidding = nil -- Clear hiding player
        end
    end
    
    LockerModule.SetScript = function(locker: Model)
        print("Set Script to", locker.Name)
        local Interactable: ProximityPrompt = locker.Interactable.ProximityPrompt
        local Hide_Exit_Event: RemoteEvent = locker["Hide/Exit"]
        
        local PlayerHidding = nil
        
        -- Initialize Attributes
        if locker:GetAttribute("Avaliable") == nil then
            locker:SetAttribute("Avaliable", true)
        end
    
        local function InteractableTriggered(Plr: Player)
            print("Triggered", locker.Name)
            if Plr == nil then return end
            LockerModule.HideAndExit(Plr, locker, PlayerHidding)
        end
    
        Interactable.Triggered:Connect(InteractableTriggered)
        Hide_Exit_Event.OnServerEvent:Connect(function(plr)
            LockerModule.HideAndExit(plr, locker, PlayerHidding)
        end)
    end
    
    return LockerModule
    

    How It Works

    1. Hiding Logic
      • When a player interacts with a locker:
        • Their character is moved to InsidePos.
        • The camera switches to InsideCam (e.g., a close-up view inside the locker).
        • The locker is marked as unavailable.
    2. Exiting Logic
      • When a player interacts again:
        • They’re moved to OutsidePos.
        • The camera resets.
        • The locker becomes available again.
    3. Safety Checks
      • Prevents players from exiting a locker they didn’t hide in.
      • Ensures parts like InsidePos and InsideCam exist before use.

    Setup Instructions

    1. Locker Structure
      • Each locker should have:
        • InsidePos: A part where the player’s character is teleported during hiding.
        • OutsidePos: A part where the player returns after exiting.
        • InsideCam: A part/camera position for the hiding view.
        • Interactable → ProximityPrompt: For triggering hide/exit.
        • Hide/Exit → RemoteEvent: For client-server communication.
    2. Initialize Attributes
      • Set Avaliable = true in the locker’s properties or via code.

    Optional Enhancements

    • Animations: Add opening/closing animations for the locker door.
    • Sound Effects: Play a sound when hiding/exiting.
    • Cooldown: Add a short delay after exiting to prevent spamming.
    • Respawn Handling: Disconnect hiding logic if the player dies (listen to plr.CharacterRemoving).

    Testing Tips

    • Test hiding/exiting with multiple players.
    • Ensure the camera transitions work smoothly.
    • Check for errors if parts like InsidePos are missing.

    Let me know if you’d like help implementing animations, AI behavior, or additional features! 🎮

  3. User

    how can i make a number from 0.6 to 1.4 change according to another number, Min: 25 (0.6) Max: 5 (1.4)

  4. Assistant

    To map a number from 25 (min) → 5 (max) to 0.6 (min) → 1.4 (max), you need a linear interpolation (lerp) formula that reverses the input range. Here's how to do it:


    Mathematical Formula

    You want:

    • When input = 25, output = 0.6
    • When input = 5, output = 1.4

    This is a reverse linear mapping (since the input decreases while the output increases). The formula is:

    function remap(input, inMin, inMax, outMin, outMax)
        local t = (input - inMin) / (inMax - inMin) -- Normalized value (0 to 1)
        return outMin + t * (outMax - outMin)
    end
    

    Use it like this:

    local input = 25 -- Example input (change this dynamically)
    local output = remap(input, 25, 5, 0.6, 1.4)
    print(output) -- Output will range from 0.6 to 1.4
    

    Explanation

    • inMin = 25 (start of input range)
    • inMax = 5 (end of input range)
    • outMin = 0.6 (start of output range)
    • outMax = 1.4 (end of output range)

    The formula calculates t (a normalized value from 0 to 1) based on the input's position in the inverted input range, then maps it to the output range.


    Example Values

    InputOutput
    250.6
    151.0
    51.4

    Direct Formula

    If you don't want a reusable function, use this one-liner:

    local output = 0.6 + (1.4 - 0.6) * ((25 - input) / (25 - 5))
    

    Use Case in Your Game

    For example, if you’re using this to adjust AI difficulty or camera sensitivity:

    local aiDifficulty = remap(playerDistance, 25, 5, 0.6, 1.4)
    

    This makes the AI "harder" (higher value) as the player gets closer (playerDistance decreases).

    Let me know if you need help integrating this into your existing code! 🎮

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.