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

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

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 comment

1 answer

✓ Accepted answer

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)

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