local Service = game:GetService("UserInputService")
local event = game.ReplicatedStorage:WaitForChild("CameraEquip")
local Equipped = false
Service.InputBegan:Connect(function(KeyboardInput)
if KeyboardInput.KeyCode.Name == "G" then
if Equipped == false then
event:FireServer(true)
Equipped = true
else
event:FireServer(false)
Equipped = false
end
end
end)
Edit:
and now that I think of it, you don’t need this:
There is still the problem of the tool disappearing, unfortunately. I don’t know why it’s still happening because I am not changing the parent of the tool like before.
It means that it is waiting forever for the tool do this:
Event.OnServerEvent:Connect(function(Player, Equip)
local humanoid = Player.Character:WaitForChild("Humanoid")
local tool = Player.Backpack:FindFirstChild("Camera") or Player.Character:FindFirstChild("Camera")
if Equip and tool then
humanoid:EquipTool(tool)
elseif not equip and not tool then
humanoid:UnequipTools()
end
humanoid.Died:Connect(function()
humanoid:UnequipTools()
end)
end)
It might be a problem with another script because when the tool disappears, I’m pretty sure it is being destroyed and not returned to the player’s backpack.
I don’t think those scripts are the culprit/s, firstly test to see if the tool is actually destroyed, if it is check if you have any other scripts that make changes to the tool.
Just posting the two scripts together, I’ve also added a statement to the local script to make the backpack invisible so a player can’t use both ‘1’ and ‘G’ to equip/unequip the tool.
Script in ServerScriptService:
local Event = Instance.new("RemoteEvent")
Event.Name = "CameraEquip"
Event.Parent = game.ReplicatedStorage
Event.OnServerEvent:Connect(function(Player, Equip)
local humanoid = Player.Character:WaitForChild("Humanoid")
local tool = Player.Backpack:FindFirstChild("Camera") or Player.Character:FindFirstChild("Camera")
if Equip == true then
humanoid:EquipTool(tool)
else
humanoid:UnequipTools()
end
end)
Local script in StarterPlayerScripts:
local Service = game:GetService("UserInputService")
local event = game.ReplicatedStorage:WaitForChild("CameraEquip")
local Equipped = false
local CoreGui = game:GetService("StarterGui")
CoreGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
Service.InputBegan:Connect(function(KeyboardInput)
if KeyboardInput.KeyCode.Name == "G" then
if Equipped == false then
event:FireServer(true)
Equipped = true
else
event:FireServer(false)
Equipped = false
end
end
end)
Thanks for that. I put it as the solution so people looking at this post don’t have to scroll through all the comments. I am going to put the scripts and tool in a baseplate alone and see if that works. That way I will know if it is another script causing the disappearing problem.