In my game I disabled the inventory on the bottom of the screen so I have to make a script to change tools. It works well but there's one problem and that is that you can press 1 or 2 over and over and you'll be holding both weapons and a bunch of them will clone in to the character.
Script (In a local script):
wait()
local p = game.Players.LocalPlayer
local h = p.Character.Humanoid
local e = p:GetMouse()
local down = false
e.KeyDown:connect(function(key)
if key:lower() == "1" and not db then
down = true
p.Backpack.LinkedSword:Clone().Parent = p.Character
a = p.Character:findFirstChild("PaintballGun")
a:Destroy()
end
end)
e.KeyUp:connect(function(key)
if key:lower() == "2"then
down = true
p.Backpack.PaintballGun:Clone().Parent = p.Character
b = p.Character:findFirstChild("LinkedSword")
b:Destroy()
end
end)
EDIT: After using Fattycat17's answer, I get this error message:
13:33:03.755 - FindFirstChlid is not a valid member of Model 13:33:03.758 - Script 'Players.Player1.Backpack.Equip', Line 12 13:33:03.760 - stack end 13:33:03.761 - Disconnected event because of exception

8 comments
that's for something that I don't need anymore,I can remove it
Okay and also I tried the pcall one and it said it couldn't find "FindFirstChild".
Ah-ha that is funny I looked over the fact that you use "findFirstChild" use "FindFirstChild"
I am using "FindFirstChild"
Ah then that might be roblox being stupid again try putting Game:GetService"Players".LocalPlayer.CharacterAdded:wait() at the top of the script
"FindFirstChlid is not a valid member of Model" ... "Chlid" ... C H I L D Ha-ha don't worry we all have those days filled with typos
Thanks
No problem! Feel free to ask any other questions here @ scripting helpers! :D