Alternative for .Touched event

I made some blocks that give players a boost using the .Touched event. But it is not reliable(for example, I can walk on blocks and it doesn’t give me any effects). Is there any other way?

(I don’t want to use Region3 cause there are a lot of blocks.)

I think you need to be a bit more specific on what you are trying to achieve.
And possibily some information and screen-shots of what you want.

maybe you are using the event wrong?
or perhaps it’s running infinite amount of times?

You could use the touchingPart or humanoidPart

1 Like

Sometimes, the .Touched event don’t work probably. For example, I could walk on the block and it wouldn’t give me any effects

Are you detecting your character properly?
maybe it’s detecting a part other than your character.

Yes, I am. I used an if statement to check if that is a player.

How to use them? I haven’t heard of that before.

Are you using it as:

-- Touch event
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
end
end)

GetTouchingParts() basically returns an array of all the parts its touching.

Note - Both part must be canCollided

@FlashFlame_Roblox
Also you can use a combination of

.Touched and .TouchEnded

Yes.
(30 chars is amazing. Thanks Roblox.)

I thought about the combination but yet again, I can still walk on blocks and don’t have any effects.

Can you post your script please?

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		hit.Parent.Humanoid.Health = 0
	end
end)

This might help you out:

It uses a combination of Region3 and Raycasting to check when a player enters a ‘zone’.

Simply do:

local touchParts = your.group.of.blocks
local zone = Zone.new(touchParts)
zone.playerAdded:Connect(function(player)
	-- give boost
end)
zone.playerRemoving:Connect(function(player)
	-- remove boost
end)
zone:initLoop()
5 Likes

Thats pretty weird, I just tested it and it worked. Are you sure this code is inside a server script?

1 Like

my advice is to look into Region3 it requires a little more work but it runs very well for me and almost no lag.

1 Like

You can use .Magnitude, the distance in studs between 2 objects, or :GetToucingParts(), which returns an array on the parts that intersect with the part.

2 Likes

Can I group all the blocks to do that or I have to do it for every single blocks?