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)
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)
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?