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

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

Asked by
4o4g 2
3 years ago

I am new and still learning to code in lua

1 answer

Log in to vote
0
Answered by
dukzae 0
3 years ago
Edited 3 years ago

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
Ad

Answer this question