the Touched event as far as I understand accounts for when a part is touched by another part (with both cancollide properties on) at least, in the way I'm trying to use it.
however, does this event account for if a part is being consistently touched (ex. a player just stands on the part, or object) or is there another event that does? TouchEnded checks to see if a part ''stops touching another part'', so I am wondering about this.
The reason this happens is due to the Idle Animation roblox plays when a character is stationary. If you were to move you would also still get more than one touched event firing at once.
I actually looked into this and found my own method. I'll be using the TouchEnded
event now as well.
-- regular script in part script.Parent.Touched:connect(function(p) --code later end)
-- regular script in part script.Parent.Touched:connect(function(p) script.Parent.TouchEnded:wait() --code later end)
local value = 0 script.Parent.Touched:connect(function(p) value = value+1 script.Parent.TouchEnded:wait() value = value-1 end)
local value = 0 script.Parent.Touched:connect(function(p) value = value+1 script.Parent.TouchEnded:wait() wait(.35)-- Experiment with this number value = value-1 end)
That will actually work. Now anywhere in our script we can check if a player in touching the part by checking if "value" is greater than 0. Here's a loop to demonstrate it working,
local value = 0 script.Parent.Touched:connect(function(p) value = value+1 script.Parent.TouchEnded:wait() wait(.35) value = value-1 end) while wait() do if value > 0 then print("I'm Being Touched!") else print("I'm not being touched") end end
Now whenever you stand on the part it will print("I'm being touched"), and anytime no one is touching the part it will print("I'm not being touched").
I hope I helped you some.
Good Luck!