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

Keybind help,I have keybind that when i press R everyone that touches me dies how to undo?

Ok This is the Code I have, When I Press R its activating the "Touch for kill" but I need also an Undo (When i press R again it will turn off and anyone that touch me won't die)

local plr = game:GetService'Players'.LocalPlayer
local char = plr.Character
local hum = char:FindFirstChildOfClass'Humanoid'
mouse = plr:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "r" then
wait()
if hum then
hum.Touched:connect(function(hit)
if hit.Parent:IsA'Model' and hit.Parent:FindFirstChildOfClass'Humanoid' and hit.Parent ~= char then
hit.Parent:BreakJoints()

end
end)
end
end
end)

2 comments

0

You could try using a variable

0

but how , someone told me somthing with "DeBounce"

1 answer

I made some comments. If it doesn't work then let me know, and I'll fix it. :)

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local connections = {} --table for event connections

mouse.KeyDown:connect(function(key)
	if key == "r" then
		if #connections == 0 then --check if there's any current connections
			if char then
				for _,Object in pairs (char:GetChildren()) do
					if Object:IsA("BasePart") then --condition passes on all parts directly inside the character model
						table.insert(connections, Object.Touched:connect(function(hit) --insert new connection into table
							local findPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
							if findPlayer then --
								findPlayer.Character:BreakJoints()
							end
						end))
					end
				end
			end
		else
			for _,Object in pairs(connections) do --destroy connections if there are any left
				Object:disconnect()
			end
			connections = {}
		end
	end
end)

2 comments

0

Thanks its working but there is a way that if i press the button its will do it again? because if i press "R" again after i destroyed all the connection nothing happens

0

I think I fixed it, try it and let me know :p

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