How can i trigger a touched without having to move

thats one finish line brick and kill brick. if i do only the kill variable it will just kill everyone

‘part’ is a finish line in a race minigame i made

my problem with the script is that the players have to be moving during the touched event for the brick to kill them

Is part the finish line? Why do both touch connects you only need one.

1 Like

the first touch is for the finish line and the second touch is for the killbrick to kill everyone behind

Maybe try using raycast and cast the ray every something and if it hits the player then deal damage to the player, or just move the lasers by like 0.001 every something and it should do the same.

if i constantly have the killbrick killing, it would kill all the players. my issue is that my touched events require player movement to fire

to clarify, i mean that touched events dont allow me to do anything unless the player is moving

as stated above you are creating a connection each time the first part is touched for the kill you need this connection created seperate else it won’t be there until something touches the part

also if these touch events don’t work you can use :GetTouchingParts() to find out if a part is touching it without the part having to move just use it with a loop most likely

the correct way you would normally write the script is like this:

local part = script.Parent
local kill = script.Parent.Parent.KillBrick

	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if Player then   -- this prints when a player's cahracter touches the finish line
		print(Player.Name, ' playertouchedFinish')

	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local Humanoid = hit.Parent:FindFirstChild('Humanoid')
	if Player and Humanoid then  -- if this is a player's character and humanoid is found
		Humanoid.Health = 0

but see here in this script, the kill brick is always running. in my game, the kill brick is an invisible brick that covers the entire map. if i do this, every single player would die. my issue is just that the touched event requires a player to move to work

thats why i added the killbrick touched event inside the finish line one. its because i need the finish line touch event to run first

thats exactly what i want in my script. that is not my issue. my issue is that i want it to kill everyone who is inside the kill brick but it doesnt kill the players if they arent moving

This should work to fit your needs; let me know if there’s any errors.

part = script.Parent
kill = script.Parent.Parent.KillBrick

local function GetTouchingParts(part)
	local connection = part.Touched:Connect(function() end)
	local results = part:GetTouchingParts()
	return results

	local blacklisted
	if hit.Parent:FindFirstChild("Humanoid") then
		blacklisted = hit.Parent.Name
	local touching = GetTouchingParts(kill)
	for i, v in pairs(touching) do
		if v.Parent:FindFirstChild("Humanoid") and v.Parent.Name ~= blacklisted then
			v.Parent.Humanoid.Health = 0

    blacklisted = nil

Basically, when the player touches the finish line, it will kill all other players that are currently inside of the killBrick except the player that touched the finish line.

And also, I found this method of using :GetTouchingParts() from here.

EDIT: Added blacklisted = nil to reset the variable after killing the other players.


You could use a whitelist blacklist system like @MJTFreeTime did

1 Like

Here’s a simple script that I wrote up quickly that may work for you. Instead of requiring a separate killbrick it simply gets all players in the game and if they are not the winner it kills them.

local Players = game:GetService("Players")

local finishLine = workspace.FinishLinePart -- finish line part

	if Players:GetPlayerFromCharacter(obj.Parent) then
		local winner = Players:GetPlayerFromCharacter(obj.Parent)
		for i, player in pairs(Players:GetChildren()) do
			if player ~= winner and player.Character then
				player.Character.Humanoid.Health = 0
1 Like

i think this script should work but this only works if both players are touching the finish line im going to edit it accordingly and type here if anything goes wrong

Oh, I’m not sure I understand what you’re saying. From what I understand, you want all other players besides the player who touched the finish line to die; directly after the player touches the finish line that is. The script I wrote will wait for any one person to touch the finish line. When this happens, it will kill all other players besides the single person who touched the finish line. So it shouldn’t work only if multiple players are touching the finish line, but rather when a single player does.

i just tried this solution and it worked! thank you! and thank you to everyone else who was here to help me with this issue!

1 Like

i meant that i wanted everyone touching a killbrick to die upon a player touching the line

That’s exactly what the script I wrote does. It will kill all players that are touching the killbrick except the player who touched the finish line, upon any player touching the line.