I’m currently making a script where you can mop up spills, I have everything working but the TouchEnded fires when the player is actually touching the part. I’m looking for a different way of using TouchEnded as it’s very buggy. if you have any alternatives make sure to post
Yeah because magnitude is checking how close is the part so if you set it very precisely you could.
The problem is that it might not work if you touch a corner and just if the mop is closer to the center
GetTouchingParts() returns a table of all the parts touching the objects, meaning you can cycle through all said parts to see if you can find the mop.
Example of implementing this into your code:
local spill = script.Parent
local TweenService = game:GetService("TweenService")
local RunService = game:GetService('RunService')
local partChanges = {
Size = Vector3.new(0.07, 1.15, 1.15),
}
local tweenInfo = TweenInfo.new (
3,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false,
0.1
)
local tween = TweenService:Create(spill, tweenInfo, partChanges)
script.Parent.Activated:Connect(onActivation)
local function checkIfTouchingMop()
local touching = spill:GetTouchingParts()
for i = 1,#touching do
local part = touching[i]
if part.Parent.Name == 'Mop' then
return true
end
end
end
spill.Touched:Connect(function()end)
while wait() do
if checkIfTouchingMop() then
if tween.PlaybackState ~= Enum.PlaybackState.Playing then
tween:Play()
end
else
if tween.PlaybackState ~= Enum.PlaybackState.Paused then
tween:Pause()
end
end
end
script.Parent.TouchEnded:Connect(function(plt)
wait(.1)
if plt.Parent.Name == "Mop" then
print("kk")
-- tween:Pause()
end
end)
If that really doesn’t work, as previously mentioned, you could use GetTouchingParts.
function searchForNameInTable(table,name)
for i,v in pairs(table) do
if v == name then
return true
end
end
return false
end
script.Parent.Touched:Connect(function(touch)
if touch.Parent.Name == "Mop" then
tween:Play()
repeat wait() until (searchForNameInTable(script.Parent:GetTouchingParts(),"Mop")==false)
end
end)
there’s probably a better way to do it still but those are viable options
the red part is the spill,
the blue part is the mop,
and the purple one is the magnitude,
even if I don’t really recommend it isn’t very buggy and like what @EDmaster24 said
and you could make it check if they are touching