You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m making my roblox horror game a first person with body script, and need my mouse to unlock when I open the settings panel. -
What is the issue? Include screenshots / videos if possible!
The mouse unlocks, but I can’t see my settings panel at all. -
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
AI, Dev Forum, friends, other devs, so much
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
StarterGui\FirstPersonBody
repeat wait() until game:GetService("Players").LocalPlayer.Character ~= nil
local runService = game:GetService("RunService")
local input = game:GetService("UserInputService")
local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SettingsToggle = ReplicatedStorage:WaitForChild("SettingsToggle")
local NauseaEvent = ReplicatedStorage.Remotes:FindFirstChild("NauseaEvent")
local player = players.LocalPlayer
local camera = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- Config
local CanToggleMouse = {allowed = false; activationkey = Enum.KeyCode.F}
local CanViewBody = true
local Sensitivity = 1.5
local Smoothness = 0.1
local FieldOfView = 90
-- Camera vars
local CamPos, TargetCamPos = camera.CFrame.Position, camera.CFrame.Position
local AngleX, TargetAngleX = 0, 0
local AngleY, TargetAngleY = 0, 0
local running = true
local freemouse = false
local inCutscene = false
local settingsOpen = false
local nauseaIntensity = 0
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = FieldOfView
input.MouseBehavior = Enum.MouseBehavior.LockCenter
-- Settings panel toggle signal
SettingsToggle.Event:Connect(function(state)
settingsOpen = state
end)
-- Nausea effect support
if NauseaEvent then
NauseaEvent.Event:Connect(function(intensity, duration)
nauseaIntensity = intensity
task.delay(duration, function()
nauseaIntensity = 0
end)
end)
end
-- Hide player body if needed
local function updatechar()
for _, v in pairs(character:GetChildren()) do
if CanViewBody then
if v.Name == 'Head' then
v.LocalTransparencyModifier = 1
v.CanCollide = false
end
else
if v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
v.LocalTransparencyModifier = 1
v.CanCollide = false
end
end
if v:IsA("Accessory") or v:IsA("Hat") then
local handle = v:FindFirstChild("Handle")
if handle then
handle.LocalTransparencyModifier = 1
handle.CanCollide = false
end
end
end
end
-- Input movement (mouse and touch)
input.InputChanged:Connect(function(inputObject)
if not running or inCutscene or settingsOpen then return end
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local delta = Vector2.new(inputObject.Delta.x / Sensitivity, inputObject.Delta.y / Sensitivity) * Smoothness
TargetAngleX = math.clamp(TargetAngleX - delta.y, -80, 80)
TargetAngleY = (TargetAngleY - delta.x) % 360
end
end)
input.TouchMoved:Connect(function(inputObject)
if not running or inCutscene or settingsOpen then return end
local delta = Vector2.new(inputObject.Delta.x / Sensitivity, inputObject.Delta.y / Sensitivity) * Smoothness
TargetAngleX = math.clamp(TargetAngleX - delta.y, -80, 80)
TargetAngleY = (TargetAngleY - delta.x) % 360
end)
-- Toggle freemouse
input.InputBegan:Connect(function(inputObject, gpe)
if inputObject.UserInputType == Enum.UserInputType.Keyboard then
if inputObject.KeyCode == CanToggleMouse.activationkey and CanToggleMouse.allowed then
freemouse = not freemouse
elseif inputObject.KeyCode == Enum.KeyCode.Tab and not gpe then
settingsOpen = not settingsOpen
SettingsToggle:Fire(settingsOpen)
end
end
end)
-- Camera update
runService.RenderStepped:Connect(function()
if not running then return end
if settingsOpen then
input.MouseBehavior = Enum.MouseBehavior.Default
else
input.MouseBehavior = Enum.MouseBehavior.LockCenter
end
if not inCutscene then
camera.CameraType = Enum.CameraType.Scriptable
updatechar()
CamPos = CamPos + (TargetCamPos - CamPos) * 0.28
AngleX = AngleX + (TargetAngleX - AngleX) * 0.35
local dist = TargetAngleY - AngleY
dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist
AngleY = (AngleY + dist * 0.35) % 360
local nauseaX = math.sin(tick() * 2) * nauseaIntensity
local nauseaY = math.cos(tick() * 2) * nauseaIntensity
camera.CFrame = CFrame.new(head.Position)
* CFrame.Angles(0, math.rad(AngleY), 0)
* CFrame.Angles(math.rad(AngleX + nauseaX), math.rad(nauseaY), 0)
* CFrame.new(0, 0.8, 0)
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, math.rad(AngleY), 0)
character.Humanoid.AutoRotate = false
end
end)
StarterGui\Settings\open\LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SettingsToggle = ReplicatedStorage:WaitForChild("SettingsToggle")
local UserInputService = game:GetService("UserInputService")
script.Parent.MouseButton1Click:Connect(function()
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
SettingsToggle:Fire(true)
script.Parent.Visible = false
script.Parent.Parent.Background.Visible = true
script.Parent.Parent.close.Visible = true
end)
StarterGui\Settings\close\LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SettingsToggle = ReplicatedStorage:WaitForChild("SettingsToggle")
local UserInputService = game:GetService("UserInputService")
script.Parent.MouseButton1Click:Connect(function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
SettingsToggle:Fire(false)
script.Parent.Visible = false
script.Parent.Parent.Background.Visible = false
script.Parent.Parent.open.Visible = true
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.