Preventing player from un-equipping Gun weapons but switch guns

Here is the Whole code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local toolone = game.ReplicatedStorage.Tools:WaitForChild("M4-A1")
local tooltwo = game.ReplicatedStorage.Tools:WaitForChild("Geist17")

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
--rest of the code

local equipped = "one"

game:GetService("UserInputService").InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.One then
		if equipped ~= "one" then
			equipped = "one"
			humanoid:UnequipTools()
			humanoid:EquipTool(toolone)
		end
	elseif key.KeyCode == Enum.KeyCode.Two then
		if equipped ~= "two" then
			equipped = "two"
			humanoid:UnequipTools()
			humanoid:EquipTool(tooltwo)
		end
	end
end)

And btw i placed this is StarterCharacterScripts

It’s probably best to put it in StarterCharacterScripts, and set character to script.Parent, so it can work after a player dies.
But other than that, I think it should work.

Which part of it do i need to change?

Can you send the Whole edited code?

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local toolone = game.ReplicatedStorage.Tools:WaitForChild("M4-A1")
local tooltwo = game.ReplicatedStorage.Tools:WaitForChild("Geist17")

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
--rest of the code

local equipped = "one"

game:GetService("UserInputService").InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.One then
		if equipped ~= "one" then
			equipped = "one"
			humanoid:UnequipTools()
			humanoid:EquipTool(toolone)
		end
	elseif key.KeyCode == Enum.KeyCode.Two then
		if equipped ~= "two" then
			equipped = "two"
			humanoid:UnequipTools()
			humanoid:EquipTool(tooltwo)
		end
	end
end)

It seems not to be working not fine…

This should work in StarterCharacterScripts:

local player = game.Players.LocalPlayer
local Character = script.Parent
local humanoid = Character:WaitForChild("Humanoid")
local toolone = game.ReplicatedStorage.Tools:WaitForChild("M4-A1")
local tooltwo = game.ReplicatedStorage.Tools:WaitForChild("Geist17")

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
--rest of the code

local equipped = "one"

game:GetService("UserInputService").InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.One then
		if equipped ~= "one" then
			equipped = "one"
			humanoid:UnequipTools()
			humanoid:EquipTool(toolone)
		end
	elseif key.KeyCode == Enum.KeyCode.Two then
		if equipped ~= "two" then
			equipped = "two"
			humanoid:UnequipTools()
			humanoid:EquipTool(tooltwo)
		end
	end
end)
1 Like

wait

What about it?

Look at the Difference between the Handling of the Gun.

That’s because the first one has a viewmodel with animations.
There are various ways to do this, but I recommend looking up a tutorial. (Tools in first person don’t show any body parts)

Edit: I’m happy to help with the viewmodel if you need any, but I won’t make very large amounts of it. If you do want help from me, you should probably contact me in a DM rather than this topic.

1 Like

Hey @BriefYayyayyay , I planned to make it on like uhm…On ReplicatedStorage

Like you put on Weapons Folder and Place the guns in the folder.
And in StarterPlayerScripts is where you can place a LocalScript
Thing

You can put LocalScripts in StarterPlayerScripts, StarterGui, StarterCharacterScripts, ReplicatedFirst and StarterPack, from what I know.

What do you mean by this?

Nevermind, Uhm…Like arsenal. I changed my mind. How do i make a system like if you press Q, Your gun will switch?

You should use Roblox’s ‘Talent Hub’ to hire a scripter.

I want to. But. I do not have Robux to hire some people…