Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you fix the mouse maniplulation lock?

I was working on a script to make my gun lock then the tool is equipped. i works but then when I unequipped i it stays I've tried to set the setting to false that didn't work here's the script:

local player = game.Players.LocalPlayer local uis = game:GetService("UserInputService") local mouse = print("Holding gun")

repeat wait(1) until player.Character

local character = player.Character

local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")

animation.Name = "Idle"

animation.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=6688751964"

local animtrack = humanoid:LoadAnimation(animation)

script.Parent.Equipped:connect(function() mouse = true if mouse == true then uis.MouseBehavior = Enum.MouseBehavior.LockCenter end animtrack:Play()

end)

script.Parent.Unequipped:connect(function() mouse = false if mouse == false then uis.MouseBehavior = Enum.MouseBehavior.LockCenter == false end animtrack:Stop()

end)

2 answers

✓ Accepted answer

Click "View Source" in the top right, then copy the code and paste it in your script

local player = game.Players.LocalPlayer 
local uis = game:GetService("UserInputService") 
local mouse = player:GetMouse()

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")

animation.Name = "Idle"
animation.AnimationId = "http://www.roblox.com/asset/?id=6688751964"
animation.Parent = script.Parent

local animtrack = humanoid:LoadAnimation(animation)
local equipped = false

script.Parent.Equipped:connect(function() 
	equipped = true 
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	animtrack:Play()
end)

script.Parent.Unequipped:connect(function() 
	equipped = false 
	uis.MouseBehavior = Enum.MouseBehavior.Default
	animtrack:Stop()
end)

5 comments

0

Click "Accept Answer" beside my answer if this helped

0

It did thank you

0

I did but when I refresh it doesn't accept the answer

0

ok now it did

0

Anyways I'm glad this helped

You're defining the variable "mouse" as a function, "print("Holding gun")". Then later, you attempt to change that variable to true and false. Did you mean

local mouse = false

Also, can you put the specific error?

This discussion is preserved as it was. New answers, comments, and votes are closed.