Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I delete the weapon in a players hand from Starter Gear?

My purpose of this code is to delete the weapon in hand from the player and also the Starter Gear when a button is pressed. The code below is intended to just delete the tool from the hand. When I press the button nothing happens. How do I do this and also delete the weapon from starter gear?

game.Players.PlayerAdded:Connect(function(player)


script.Parent.MouseButton1Click:Connect(function()
	
	local Character = player.Character or player.CharacterAdded:Wait()
	--local player = game.Players:GetPlayerFromCharacter(Character)
	local SG = player.StarterGear
	local tool = Character:FindFirstChildOfClass("Tool")
	--local name = tool.Name
	if tool then
		tool:Destroy()
		
	end
	
	
	
end)
end)

3 comments

0

Sorry, the question is worded wrong. It's supposed to be "How do I delete the weapon in a players hand AND from Starter Gear?"

0

What type of script is this?

0

its a server script

3 answers

So something I noticed was that you are not referencing character correctly, it should be local tool = player.Character:FindFirstChildOfClass("tool"), here's the redone code for you

game.Players.PlayerAdded:Connect(function(player)


script.Parent.MouseButton1Click:Connect(function()
    local SG = player.StarterGear
    local tool = player.Character:FindFirstChildOfClass("Tool")
    if tool.isA("Tool") then
        tool:Destroy()

    end



end)
end)

4 comments

0

he already defined Character

0

the tool is still not deleting

0

I tried to debug and it seems like its not even entering the Player Added event. Is there any reason this is happening?

0

why did you make the character added anyways though, you just want to delete the tool right?

if SG:FindFirstChild(tool.Name) then
	SG[tool.Name]:Destroy()
end

Here is why your button does not do anything when pressed

You cannot get MouseButton1Click from a serverscript

You could make a localscript that uses MouseButton1Click and when you press it you can fire a remote from client

here is an example

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.remote:FireServer()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.