Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
ruwuhi 23
4 years ago

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)
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?" ruwuhi 23 — 4y
0
What type of script is this? zboi082007 270 — 4y
0
its a server script ruwuhi 23 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
he already defined Character Brandon1881 721 — 4y
0
the tool is still not deleting ruwuhi 23 — 4y
0
I tried to debug and it seems like its not even entering the Player Added event. Is there any reason this is happening? ruwuhi 23 — 4y
0
why did you make the character added anyways though, you just want to delete the tool right? ayuu_ondev 60 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
if SG:FindFirstChild(tool.Name) then
    SG[tool.Name]:Destroy()
end
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

Answer this question