So, developers i made this module that detects if A player/part isn’t touching a part or is touching a part.
So how is this useful compared to Roblox’s system?
So, first of all. when a player touches a part it uses the :GetOtherParts() function, which i think its better than Roblox thing, and the Non touching system it basically detects that if the player isn’t touching it.
So, you might be saying: “why do we use the Non touching system?”
It’s useful if you want to make like if the player touched the part, and then the player stepped out of the part.
Here is the code. The character touching system ONLY works for R15, R6 compatibility will be here soon:
local PTS = {}
function PTS.PartTouched(PartThatIsTouched: BasePart, PartThatIsTouchingThePart: BasePart)
local connection = PartThatIsTouched.Touched:Connect(function() end)
local TouchGroup = PartThatIsTouched:GetTouchingParts()
connection:Disconnect()
if table.find(TouchGroup, PartThatIsTouchingThePart) then
print(TouchGroup, TouchGroup[table.find(TouchGroup, PartThatIsTouchingThePart)])
return true
end
return false
end
function PTS.CharacterTouchedPartR15(PartThatIsTouched: BasePart, Char: Model) -- Only Works For R15, R6 Will be supported
local connection = PartThatIsTouched.Touched:Connect(function() end)
local TouchGroup = PartThatIsTouched:GetTouchingParts()
connection:Disconnect()
local rf = Char:FindFirstChild("RightFoot")
local lf = Char:FindFirstChild("LeftFoot")
if table.find(TouchGroup, rf) then
return true
end
if table.find(TouchGroup, lf) then
return true
end
return false
end
function PTS.CharacterNotTouchingPartR15(PartThatIsLeft: BasePart, Char: Model) -- Only Works For R15, R6 Will be supported, it detects if the characters right/left foot is touching on a part.
local rf = Char:FindFirstChild("RightFoot")
local lf = Char:FindFirstChild("LeftFoot")
local rconnection, lconnection = rf.Touched:Connect(function() end), lf.Touched:Connect(function() end)
local rTouchGroup, lTouchGroup = rf:GetTouchingParts(), lf:GetTouchingParts()
rconnection:Disconnect()
lconnection:Disconnect()
if not table.find(rTouchGroup, PartThatIsLeft) then
print(Char.Name.. " Isnt Touching ".. PartThatIsLeft.Name)
return true
end
if not table.find(lTouchGroup, PartThatIsLeft) then
print(Char.Name.. " Isn't Touching ".. PartThatIsLeft.Name)
return true
end
return false
end
function PTS.PartNotTouchingPart(PartThatIsTouched: BasePart, PartThatIsTouchingThePart: BasePart)
local connection = PartThatIsTouched.Touched:Connect(function() end)
local TouchGroup = PartThatIsTouched:GetTouchingParts()
connection:Disconnect()
if not table.find(TouchGroup, PartThatIsTouchingThePart) then
return true
end
return false
end
return PTS
Here is an example code, a local script located in StarterCharacterScripts:
local TouchModule = require(game.ReplicatedStorage.Modules.PartTouchedSystem)
local Char = script.Parent
local Plr = game.Players:GetPlayerFromCharacter(Char)
local Gui = Plr.PlayerGui.ScreenGui.ActivateButton
local Part = workspace.Part
while wait() do
if TouchModule.CharacterTouchedPartR15(Part, Char) then -- if the PlayerTouched The part
Gui:TweenPosition(UDim2.new(0.5,0,0.006,0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.1)
elseif TouchModule.CharacterNotTouchingPartR15(Part, Char) then -- if the Player Isnt Touching the part anymore
Gui:TweenPosition(UDim2.new(0.5,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1)
end
end
Roblox has a system called “TouchEnded” function, but it is very bad to rely on. so, this module might make it better.
This Module has a lot of bugs, like whenever you move it sometimes think you’re not touching the part, and when you stop it redetects.
Thanks for reading!
Edit: So, guys if you can give me suggestion to add/fix this module!