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

I need help with a touched event to destroy a player's tool?

Asked by 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

So I was trying to make something when if you touch something with a tool it will get taken out of your inventory and placed into the shrine. However, it will not work



local event = game.ReplicatedStorage.event local function touched() script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Beans") then script.Parent.Parent.BeanPosition.Transparency = 0 print("Player has beans!") local player = game.Players:GetPlayerFromCharacter(hit.Parent) print(player.Name.." needs their beans removed.") local light = script.Parent.Parent.Carpet.SurfaceLight light.Enabled = true player.Backpack.Beans:Destroy() script.Parent.Parent.BeanPosition.Script.Disabled = true end end) end while wait(5) do spawn(touched) end
0
:( jorcorrs 76 — 4y
0
what? VitroxVox 884 — 4y
0
Have you checked the output? DeceptiveCaster 3761 — 4y
0
yes, it says "Beans is not a valid member of Backpack" when it's in the player's inventory. jorcorrs 76 — 4y

1 answer

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

Hello, If the player has the item equipped, then the tool is in their character.. please try the script below.

local event = game.ReplicatedStorage.event
local function touched()
    script.Parent.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Beans") then
            script.Parent.Parent.BeanPosition.Transparency = 0
            print("Player has beans!")
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            print(player.Name.." needs their beans removed.")
            local light = script.Parent.Parent.Carpet.SurfaceLight
            light.Enabled = true
            hit.Parent.Beans:Destroy()
            script.Parent.Parent.BeanPosition.Script.Disabled = true
        end
    end)
end

while wait(5) do
    spawn(touched)
end

Please upvote if this works, Thank you.

Ad

Answer this question