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

How do i check if player is still touching the part?

Basically i need help on how to remake this so when the player leaves the part called RightFoot Box, it won't take any damage.It works now even if he leaves its hitbox the player still dies.

Hitboxes['Right Foot Box'].Touched:Connect(function(hit)
	
	if not is_blinded or not is_right_grab or not is_left_grab or not is_stomped or Titan.Humanoid.Health <= 0 then return end
	
	if not is_leftleg_tendon or not is_rightleg_tendon then return end
	
	local char = hit.Parent 
	
	local Player = game.Players:GetPlayerFromCharacter(char)
	
	if not Player  then return end
	
	if not char:FindFirstChild('Humanoid') then return end
	
	is_stomped = false
	
	local Stomp = Titan.Humanoid:LoadAnimation(Titan.Animations.Stomp)
	Stomp:AdjustSpeed(5)
	Stomp:Play()
	
	for i, track in pairs(Titan.Humanoid:GetPlayingAnimationTracks()) do
		if track.Name == 'Stomp' and not is_stomping then
			char.Humanoid:TakeDamage(100)
			wait(3)
			is_stomped = true
			return
		end
	end
	
	wait(Stomp.Length)
	
	char.Humanoid:TakeDamage(100)
	
	wait(1)
	
	is_stomped = true
	
end)

2 answers

to check if the player stopped touching the part:

Object.Touched:Connect(function(hit)
-- code here
end)

Object.TouchEnded:Connect(function(hit)
-- code here
end)

7 comments

0

Pretty self explanatory lol

0

I tried with that, it didn't seem to work, i have to place everything in right place, can u reorganize the script with your example, im not a scripter, i just need to fix that.

0

well, the fact you spaced out "Right Foot Box" could be one of the reasons, plus you're supposed to also explain the script. also you made is_stomped true twice lol

0

Yeah ikr, i am not really experienced thats why i asked for help.

0

Well just unspace right foot box and make is_stomped = false on line 36. tell me the results then

0

Doesn't work.

0

must be smth else all together

Ok so this might be what you are looking for. The only problem is when you are constantly going in and out of this hitbox, sometimes it will not register a hit. It is bc of the way how a server sees a player. Basically it is impossible to do a highly accurate hit reg by using one server script

local hitboxPart = script.Parent
local touchingHumanoidRootParts = {} -- we gonna save humanoid root parts that are already touching. Notice I said parts, not players

hitboxPart.Touched:Connect(function(part)

	if part.Name ~= "HumanoidRootPart" then return end -- the best option is to check for humanoid root part
	local Player = game.Players:GetPlayerFromCharacter(part.Parent) -- checking for a humanoid by your way
	if not Player then return end
	if not part.Parent:FindFirstChild('Humanoid') then return end

	if table.find(touchingHumanoidRootParts, part) then return end -- checking for this specific humanoid root part out of all humanoid root parts we saved. If there is one - ignoring this event
	table.insert(touchingHumanoidRootParts, part) -- else saving this humanoid root part so this character won't be damaged again while he is touching hitbox
	-- the rest of your script
	part.Parent.Humanoid.Health = part.Parent.Humanoid.Health - 20
end)


hitboxPart.TouchEnded:Connect(function(part)

	if part.Name ~= "HumanoidRootPart" then return end
	if not part.Parent:FindFirstChild('Humanoid') then return end

	if table.find(hitboxPart:GetTouchingParts(), part) then return end -- making sure that hitbox is no longer touching humanoid root part. If this humanoid root part found in all touching parts of hitbox then we are ignoring this event. This is a very important step and this is how we detect "fake touch events"
	if not table.find(touchingHumanoidRootParts, part) then return end -- checking for this specific humanoid root part out of all humanoid root parts we saved. If there are none - nothing needs to be done about this
	table.remove(touchingHumanoidRootParts, table.find(touchingHumanoidRootParts, part)) -- else removing this humanoid root part so this character can be damaged by this hitbox
end)

We are using a HumanoidRootPartas a main hitreg part of a character, I find it the best way how to do the thing with preventing multiple damages on a character. You probably don't understand how tables works, it is essential to understand how tables works in this situation. If you have questions, leave them below (but i have to go to sleep so i can only answer tomorrow)

what are tables

table functions such as table.find(), table.remove()

BasePart:GetTouchingParts()

1 comment

0

It was tested in an empty game on a big semitransparent non collidable part

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