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

Why does this gui when click destroy the sword in lighting?

Asked by
duckyo01 120
8 years ago

I'm trying to make it destroy the sword in the backpack.

local Player = script.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Down:connect(function(OnClick)
    if Player.Character:FindFirstChild('Sword') == nil then
        local TehSword = game.Lighting:FindFirstChild('Sword')
        TehSword.Parent = Player.Backpack:Destroy()


    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago
local player = game.Players.LocalPlayer
local objname = "Sword"
script.Parent.MouseButton1Down:connect(function(OnClick)-- on click
if player.Character then -- checks if theres a character
if player.Backpack:FindFirstChild(objname) ~= nil then -- checks if the obj exists in the character
player.Backpack:FindFirstChild(objname):remove() -- if its there it will destroy
    end
end)

0
Always use Destroy() when possible since remove() is deprecated! UserOnly20Characters 890 — 8y
Ad

Answer this question