While touching do - tutorial

This is a tutorial because i couldnt find a actual forum telling you how to do it <3

local touching = false

script.Parent.Touched:Connect(function(hit) --checks if the player touched
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		touching=true	
	end
end)

script.Parent.TouchEnded:Connect(function(hit) --checks when the player stopped touching
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		touching=false	
	end
end)

coroutine.wrap(function()
	while touching do -- While touching loop
		task.wait()
		--Your script here
	end
end)()

Hope i helped

1 Like

You never checked to see if the player actually touched the part and wait() is deprecated.

This is so poorly made, just use zone plus lol

I uploaded the old verison mb… you can get the player using the hit value from the function…

Thank you for this tutorial, it will help me a lot with some of my scripting problems.

Fixed it right now, check it out!

fixed it to make it better, also there are no tutorials for begginers…

Looks better, would advise you to switch to task.wait() though

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.