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

How to make it so that whenever the player touches partA, it deletes PartB?

I am new and still learning to code in lua

1 answer

You can probably do something like this:

local partA = game.Workspace.PartA
local partB = game.Workspace.PartB

partA.touched:Connect(function(part)
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	if player then
		partB:Destroy
	end
end)

Basically it is assigning two variables to the two parts. When one is touched, it runs an anonymous function that detects what touched it, finds its parent (which, if it was a character's body part, it will find the character) and then gets the player from that character. If it finds the player, then it destroys the partB. And then, the script ends. Alternatively to the Destroy function, you could do

partB = nil

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