.Touched not working on still parts

I want to make a dome that stuns players when they get in. I tried using :GetTouchingParts() but I found out it doesn’t work on characters. Then I tried using .Touched but then found out the object has to be moving. How do I make it work?

2 Likes

Touched only works when both parts that are touching have CanTouch on. I believe it may also be tied to the CollisionGroup but I am unsure. The requirement to allow for touching is that ONE of the parts has to be unanchored. If you could show a sample that would be great!

RefAOEVFX = game.ServerStorage.RefAOEVFX

-- Don't worry about the position line and the TweenService one, it's a sword ability that creates an AOE and stuns.

local AOEVFX = RefAOEVFX:Clone()
local Grow = TweenService:Create(AOEVFX, TweenSettings, {Size = Vector3.new(50, 50, 50)})
AOEVFX.Position = Character:FindFirstChild("Torso").Position
AOEVFX.Parent = workspace
Grow:Play()
task.wait(0.3)
local Connection = AOEVFX.Touched:Connect(function(hit)
print(hit)
       if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= Character then
	        local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
	        hum.Jump = true
	        hum.Sit = true
		task.wait(1.5)
		hum.Sit = false
        end
end)
task.wait(1.5)
Connection:Disconnect()
AOEVFX:Destroy()
1 Like

You can try using this instead WorldRoot | Documentation - Roblox Creator Hub

1 Like

Alright, I’ll try it.

bruh roblox minimum text

Nope, it still doesn’t work. When I checked the return, it just prints out a table with the baseplate. However, when I killed a rig and tested it on the rig, it printed out Left Arm.

Judging by the address for RefAOEVFX, it sounds like you are running this on the server. I recommend using HumanoidRootPart as it is universal between R6 and R15. I have tried this out with the very little context that I have and the .Touched fired for me. Is this the behavior for you and do you have a copy of the output?

Update: I believe I understand this. I will have a look in a moment! ^.^

In my code, it can use any part of the character to determine if it is a character. And yes, its fine if it uses HumanoidRootPart.

Side note: I gtg for an hour, can’t respond.

Hello, the code snippet you are using seems to be working for me just fine. I provided a cylinder for RefAOEVFX and had it spawn at what is presumably the sword user (I assume this is Character). I have slightly modified the code to get the effect you wanted, which was that a player would shortly jump then immediately be put in a sit position for 1.5 seconds.

This covers the main part of the code. I added a table ‘stunnedPlayers’ to keep track of those users who were already stunned, so other parts intersecting do not cause multiple stuns at once.

local AOEVFX = RefAOEVFX:Clone()
local Grow = TweenService:Create(AOEVFX, TweenSettings, {Size = Vector3.new(50, 50, 50)})
AOEVFX.Position = Character:FindFirstChild("HumanoidRootPart").Position
AOEVFX.Parent = workspace
Grow:Play()
task.wait(0.3)
local stunnedPlayers= {}
local Connection = AOEVFX.Touched:Connect(function(hit)
	print(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= Character and not stunnedPlayers[hit.Parent] then
		stunnedPlayers[hit.Parent] = true
		local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
		hum.Jump = true
		task.wait(0.01) -- delay added to allow jump an opportunity to hop the player.
		hum.Sit = true
		task.wait(1.5)
		hum.Sit = false
	end
end)
task.wait(1.5)
Connection:Disconnect()
AOEVFX:Destroy()

I am unsure if your approach is the best way to do this as I have a suspicion that some client-sided scripting could be better than completely relying on the server. I might be wrong but the stun effect may be delayed on certain players if they receive the replication late. With a client-sided approach you are also able to temporarily disable controllers. It can also allow you to apply a force to a player directly through the local script as that doesn’t seem to be as complicated as doing it on a server. Tweening could also be smoother on the client as it would not rely on networking and the animation could be smoother. I could see exploits being a reason to avoid client-sided scripting for this though.

I am not experienced in fighting games though, so take my comments with a grain of salt. Go with what approach you find best. I do not mind being corrected on any of this. :smile:

Other than that, the code snippet you provided seemed to have worked well. If you are still having issues I would be glad to go into this further. The general rule is that one of the objects touching has to be unanchored.

Please find attached a video of my demonstration with the concept. In this one, I set the trigger to be me sending a chat message rather than a sword being swung. This was also done with my own TweenSettings though that should be irrelevant.

Nevermind about the HumanoidRootPart thing, I’m using a custom character. My game uses R6, so it should be fine using Torso.

Here is the demo you wanted:

This is very weird behavior. Do you have any CollisionGroups on any of the parts? This might cause Touched to fail. Is there anything file I can use to try this myself?

Verify that all parts involved have CanTouch enabled. You can do it through the explorer during runtime as well.

Here is a test I did on a blank baseplate with R6.


(You can also see it somewhat fails to do the sit after the jump on the first one. Increasing the delay is a good solution to this but I believe client-sided may be ideal)