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

why wont this this script execute when player isnt touching the part anymore???

I attempted to make it so when the player gets off the block it prints "not touching anymore" but it does not print

I decided to try this because the .TouchedEnded event is trash and doesnt work all the time ;(

script.Parent.Touched:connect(function(hit)
	if hit.Parent:WaitForChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		local coins = plr:WaitForChild("leaderstats"):WaitForChild("Coins")
		local candy = plr:WaitForChild("leaderstats"):WaitForChild("Candy")
		touching = true
		CEopen:FireClient(plr)
		while touching do
			wait(1)
			local touchingparts = script.Parent:GetTouchingParts()
			for i,v in pairs(touchingparts) do
				if v.Parent:WaitForChild("Humanoid") == nil then
					print("not touching anymore")
				end
			end
		end
	end
end)

3 comments

0

Why don't you try to make a TouchedEnded event?

0

because its funky, when I use a touch ended event the touched event doesnt always fire, and when it does the touch ended event does not work its weird

0

IT IS CAUSE TOUCHING = TRUE THE ENTIRE TIME

1 answer

On line 12 you use WaitForChild. That will actually "block" what you are doing and the script will at that point wait until all children that are touching the part have a Humanoid child.

if v.Parent:WaitForChild("Humanoid") == nil then

You will want to change that to FindFirstChild.

if v.Parent:FindFirstChild("Humanoid") == nil then

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