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

when you touch an object, you can get a sword and when you exit the object, remove the sword?

Asked by 3 years ago

Help me please i only can this local GetServer = game:GetService("ServerStorage")

script.Parent.Touched:Connect(function(hit) local h = hit.Parent:findFirstChild("Humanoid") if h ~= nil then local player = game.Players:GetPlayerFromCharacter(h.Parent) if player then local tool = GetServer.ClassicSword:Clone(1) tool.Parent = player.Backpack script.Disabled = true wait(.2) script.Disabled = false end end

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Warning, Scripting helpers is not a request site

Make a part and add a script

use this script

-- Detects when a part is touched

script.Parent.Touched:Connect(function(hit)
    -- Checks if its a humanoid that touches it
    if hit.Parent:FindFirstChild("Humanoid") then
        -- Gets the backpack
        local backpack = game.Players:GetPlayerFromCharacter(hit.Parent):WaitForChild("Backpack")

        -- Looping through the backpack in search for something named ClassicSword

        for _, tool in pairs(backpack:GetChildren()) do
            if tool.Name == "ClassicSword" then
                -- Destroys the tool
                tool:Destroy()
            end
        end
    end
end)
Ad

Answer this question