So what I’m trying to do is, when the backpack gui is visible then, I want the mouse to become unlocked and can be freely moved around and when the backpack gui is not visible then I want the mouse to lock back to the center of the screen.
is there a reason why this isn’t working? or is there any other way of doing this?
your looking at the MouseBehavior code
local function KeyToOpenBackpack(input)
if TextBox:IsFocused() then return end
if input.KeyCode == Enum.KeyCode[Backpack_Key] then
if Backpack.Visible == true then
UserInput.MouseIconEnabled = false
UserInput.MouseBehavior = Enum.MouseBehavior.LockCenter
Backpack.Visible = false
else
UserInput.MouseIconEnabled = true
UserInput.MouseBehavior = Enum.MouseBehavior.Default
Backpack.Visible = true
end
end
end
So I looked it up on the devforum and found something similar and now I have it fixed
thanks for anyone who tried helping
and this is my code now
local MouseBehavior
local function KeyToOpenBackpack(input)
if TextBox:IsFocused() then return end
if input.KeyCode == Enum.KeyCode[Backpack_Key] then
if Backpack.Visible == true then
UserInput.MouseIconEnabled = false
Backpack.Visible = false
MouseBehavior:Disconnect()
UserInput.MouseBehavior = Enum.MouseBehavior.LockCenter
else
UserInput.MouseIconEnabled = true
Backpack.Visible = true
MouseBehavior = game:GetService("RunService").RenderStepped:Connect(function()
UserInput.MouseBehavior = Enum.MouseBehavior.Default
end)
end
end
end