How could i do an untrap command?

I recently created a trap command that works as intended, however, I encountered difficulty when trying to make the untrap command. This is what the command currently looks like:

if args[1] == prefix.."trap" then
		if args[2] == "me" then
			
			if AllowCommandsToBeReplicated == true then
				local Clone = script.Parent.Models.TrapBase.Union:Clone()
				Clone.Parent = workspace
				Clone.CFrame = plr.Character.HumanoidRootPart.CFrame
				Clone.Name = plr.Name
			else
				if game.Workspace:FindFirstChild('TrapFor_'..plr.Name) then
					return
				else
					local Clone = script.Parent.Models.TrapBase.Union:Clone()
					Clone.Parent = workspace
					Clone.CFrame = plr.Character.HumanoidRootPart.CFrame
					Clone.Name = plr.Name
				end
			end

-- More Code But not needed to be shown.

When attempting to make the untrap command, I initially considered checking the Workspace for the player’s name, but since players are typically located in the Workspace, I thought I could check if the object’s name is the player’s name and if the classname is a UnionOperator. Can anyone suggest an improved approach?

The trap command that works:

i know its not the best way to go with but in the time being i thought
it could do the job, and it does so yea.

Only thing im really strugiling with is the untrap command.

Check if the trap for a player exists. If it does, destroy it. If not, return nothing :slight_smile:

Also don’t make the clone name = to the player name. It will make things confusing since your player already has that name

i know thats why i said in the post that its suppose to also check the class name so basically find the players name in the workspace and making sure that the part with the players name :IsA(‘UnionOperator’) (union part thingy)

1 Like

alright so i tried this but it didnt work like at all, it also dosnt give me any error code

Current Script:
image

also changed the trap code a bit

Allright i fixed it, for some reason instead of using the untrap thing in another if statement i had to put it in the same one with the trap one and than just use elseif instead of if again, not sure why but ig it works like that?

image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.