My script is supposed to equip a flashlight every time I hit "f", and remove the flashlight if it is already equipped. It's not working. Can anyone help?
BP = script.Parent -- LocalScript is placed in the player's Backpack. FL = BP.Flashlight char = BP.Parent.Character -- Finds character. Mouse = game.Players.LocalPlayer:GetMouse() Mouse.KeyDown:connect(function(key) local a = FL:clone() if key == "f" and a.Parent == char then a:remove() else a.Parent = char end end)
You are checking if "a" is in the Player, while you have set a to clone the Flashlight. You should rather check if the Flashlight is in the player. I'm not sure if this will make a difference, but might as well try.
ALSO: You are only activating the function if the F key is pressed AND the Flashlight is in the character. If the Flashlight isn't there, the function isn't activating. This is what I suspect is the problem.
BP = script.Parent -- LocalScript is placed in the player's Backpack. FL = BP.Flashlight char = BP.Parent.Character -- Finds character. Mouse = game.Players.LocalPlayer:GetMouse() Mouse.KeyDown:connect(function(key) local a = FL:clone() if key == "f" then if char:FindFirstChild("Flashlight") then char:FindFirstChild("Flashlight"):Destroy() --remove is deprecated, use destroy. else a.Parent = char end end end)
This should work, if not, let me know, and let me know if you have any errors in the output.