Give player tool that is always out

I am trying to create a tool that is always out in the players hand and can not be unequipped or dropped. To accomplish this, I tried disabling the backpack using
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
and then I try to give the player the tool by touching a part I call the dispenser
dispenser script:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local humanoid=player.Character:WaitForChild(“Humanoid”)
game.StarterPack.Tool.Unequipped:Connect(function()
humanoid:EquipTool(game.StarterPack.Tool)
end)
end
end)
Thanks

3 Likes

Please format your script correctly.

1 Like

Could you please tell me what exactly is your problem?

1 Like

Any issues exactly?

1 Like

This is actually relatively easy, all you have to do is detect when a tool is removed from the players character and reparent it to the character. Here’s what the script would look like:

local player:Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local ToolName = 'This is Optional'

player.CharacterAdded:Connect(function(char) 
	char.ChildRemoved:Connect(function(child) 
		if child:IsA('Tool') and (not ToolName or child.Name == ToolName) then
			child.Parent = char
		end
	end)
end)

i have not tested this code so if you use it tell me if it bugs.

1 Like

Reverse the order; give the tool first then disable backpack.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.