Touched:Connect not working when Player is Sitting

  1. What do you want to achieve? I have a Fireball that I want to damage the Player. I have some “Safe Seats” that protect the Player if he is sitting in them. There are other “Regular Seats” in the level that are NOT SAFE and should not protect the Player.

  2. What is the issue? I made a script on the Fireball. When it hits a Player, it should check if the Player is in the specific safe seats. If it is not in a safe seat, either standing or sitting in some other regular seat, it should cause damage.
    Everything works perfect if the player is standing. –Player takes damage.
    However, it does not work if the Player is sitting anywhere, safe seat OR regular seat. Basically the Touched:Connect function never triggers if the Player is sitting. If you are in a safe seat, or a regular seat, it is the same – nothing happens, the function is simply not triggered.

  3. What solutions have you tried so far? In my script I put a lot of Print commands to help identify the problem. If you are sitting anywhere (Safe or Not) Print(otherPart) never happens. This means that the function is never run if the player is sitting anywhere.

I’m a beginner and just learning. Thank you!! Code below:


local lava = script.Parent
local damage = 25
local DB = false

local function killPlayer(otherPart)

	print(otherPart) --This never fires if the player is sitting anywhere, this is bad, an error

	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if (humanoid ~= nil) then
		print("!!!!!!!!!!!!!!!!!!!!!!!!!I AM HUMAN!!!!!!!!!!!!!!!!!!!!!!")
		if DB == false then

			DB = true
			
			print("!!!!!!!!!!!!!!!!!!!!!!!!!SEAT CHECK!!!!!!!!!!!!!!!!!!!!!!!")
			print(humanoid.SeatPart)
			
			if humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat1 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat2 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat3 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat4 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat5 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat6 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat7 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat8 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat9 or
				humanoid.SeatPart == game.Workspace.Sal.Body.Sal_Seat10 or
				humanoid.SeatPart == game.Workspace.Sal.HeadMain.SeatHead or
				humanoid.SeatPart == game.Workspace.Sal.Tail.SeatTail then
				
				print("!!!!!!!!!!!!!!!!!!!!!!!!!Safe and Sitting on SAFE SEAT!!!!!!!!!!!!!!!!!!!!!!!") --This print never runs.  This proves the function never fired.
				
			else
				humanoid:TakeDamage(damage)
				local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent)
				OuchSFXEvent:FireClient(player)
				print("Yellow  Fireball has caused damage to Player.")  --This works.  Good!
				wait(1)
			end
			
			DB = true
			
		end
	end
end

lava.Touched:Connect(killPlayer)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Try replacing local function with a normal function. That would be the only fix I have for you.

Thanks for the suggestion CommanderBot. I removed the word “local” from the function. Therefore: “local function killPlayer(otherPart)”, now reads: “function killPlayer(otherPart)”

Unfortunately, it still behaves the exact same. Thank you for trying, though.

If anyone else has suggestions, I’d be very grateful. Thank you.

I ran a little test of my own and found that the Touched event does fire even if the given part makes contact with a seated character.

Can you confirm that the function is entirely not firing? If possible, could you also send a video of this occurrence?

run the game in the server when the fireball launches. Click the fireball. You can see the hitbox. Is the hitbox touching the user on the seat?

Thank you xendatro and PoliBlox,

@PoliBlox, Yes, I have a huge hit box (over 100 studs). It moves with a tween and always passes over the player. It actually hurts the player if he is not sitting on something (this is good). However, when sitting on anything (not just the special safe seats) the damage does not work. See attached images.


@xendatro Thank you for running a test!! Interesting Touched event normally works with a seated character. I believe my function is entirely not firing. The reason I believe this is I have a bunch of Print commands in the script.

If the player is standing, very first line “Print(otherPart)” works, along with the rest of the script.

However, if the player is sitting (on the correct safe seats - or the incorrect other seats), very first line “Print(otherPart)” DOES NOT work. So nothing at all happens in my Output, on touch contact.

I’m going to see if I can get a video up in a few minutes.

BTW, thank you very much for helping!!

I found another potential issue. It seems like you’re setting your debounce (DB) to true (which it already is) instead of false after it has hit a Humanoid. Though, this would still not explain why your function is entirely not firing.

@xendatro Thank you again, I’ll look closer at the debounce.

But, here is the promised video. First, the yellow fire ring comes. The player is standing so it hits the player - damage works. Next, the player sits in the wrong seats (RED dragon seats are not safe for YELLOW fire). The player should be damaged. However, sitting in the wrong seats still protects the player. Finally, the player stands again, and is hit by the third and final fire ring. It works, and damages the player.

robloxapp-20211204-2046329.wmv (4.9 MB)

@xendatro debounce is now fixed. You were right, I switched true to false. Thank you!! However, the original problem still remains.

Here is some interesting additional information. I have another DIFFERENT time in the game where the main script checks if all the players are sitting on the correct dragon. This is NOT triggered by a touched:connect event (like the problematic Fire Ring Script). This is just a function in my main script. But it works great!! It is basically the same as the Fire Ring, but without touch:connect. So I am thinking there is really something wrong with my touch:connect while sitting.

Thank you again for any help with this. See similar function below.

local function checkIfPlayerSitSplashy()--Seat check
	for i,v in pairs (game.Players:GetPlayers()) do
		if v.Character then
			if v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat1 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat2 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat3 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat4 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat5 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat6 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat7 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat8 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat9 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Body.Splashy_Seat10 or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.HeadMain.SeatHead or
				v.Character.Humanoid.SeatPart == game.Workspace.Splashy.Tail.SeatTail then
			else
				--v.Character.Humanoid.Health = 0
				v.Character.Humanoid:TakeDamage(damage)
				OuchSFXEvent:FireClient(v)
			end
		end
	end
end

I really dont know how this would fix it but maybe you could change that at the bottom and make this:

lava.Touched:Connect(function(otherPart)

Does the lava has canCollide to false?

@ Mystxry12,
Thank you. Yes canCollide is false.


I do not want it to push the player. Just pass through and hurt the player. See attached image.

One buggy thing about BasePart.Touched event is that if the part is anchored and is touching a part, it will not fire. Are you sure your lava or fireball is unanchored?

@Zach, I will try this and let you know soon.

If its non-collide how can it detect collision?

image

As long as the CanTouch property is ticked, it will always fire the Touched event when it hits something.

Also @SuperPizzaShark, are you sure your lava or fireball is unachored? Because if it is, then the Touched event will not fired due to its reliability on physics.

Okay, I’ve done some more experimentation, and I’ve found out a few pieces of information, the main piece being something that I have run into many times myself.

Let’s set up a scenario, part a and part b, both are anchored.
I have noticed in the past that when part a’s position is updated to be in contact with part b, the touched event does not fire (remember that they are both anchored). This led me to the conclusion that the physics system requires at least one of the two given parts to be moving “naturally” (through physics, such as like a falling part). However, in my scenario, since both parts are not moving naturally (they are anchored!) their respective touched events do not fire, even though they are placed within each other.

To translate this into your case, I assume you’re using some sort of artificial positioner that constantly updates the position of the lava part instance (such as a BodyVelocity or LinearVelocity). This implies that when the lava object meets a “naturally” non-moving part, the touched event will not fire. I tested this theory out and concluded that the result isn’t reliable. At some points the touched event fired, and at other times — without changing anything — the same event did not fire. This basically summarizes what @ItzMeZeus_IGotHacked just said.

In your case, the character is always moving while standing because of server-side animations. However, when the character sits I believe all of the parts come to a complete standstill. This would explain why the touched event does not fire while your character is sitting.

To confirm this, could you tell us if the dragon part(s) are being printed in the Touched event as well? I assume the dragon part(s) do not move, so they should not fire in the Touched event.

Edit: Some of this information is wrong. See below.

“If its non-collide how can it detect collision?”

@Mystxry12 I’m a new programmer, so I don’t really know. However, I think the CanTouch allows the collision detection. I think the CanCollide, will just push the player, instead of passing over. The good news is it works when the player is standing. Thoughts? Thank you again!!

**edit, thank you notzeussz. We were typing the same thing!!