I made a throwing ball, and I ran a touching event on it that simply checks if the part that the ball touched is not the ball itself or anything that DescendantOf player (anything that the player have or part of him) then print the part name and Disconnect the touching event. the problem is that sometimes the ball breakthrough things for example if there are two walls one after another and I shoot the first wall some times it tells me that the ball touched the second wall.
I set the NetworkOwner to the player, and I have noticed that when I increase the speed of the ball the breakthrough happens more. it seems that there is a delay in the touch event but I am not sure about it.
This is the code:
local playerCharacter = workspace:FindFirstChild(script.Parent.Owner.Value) -- get player character
script.Parent.PrimaryPart:SetNetworkOwner(game.Players:GetPlayerFromCharacter(playerCharacter))
print("network owner :",script.Parent.PrimaryPart:GetNetworkOwner())
local touchConn
local function onTouched(part)
if part:IsDescendantOf(script.Parent) or part:IsDescendantOf(playerCharacter) then return end
touchConn:Disconnect()
print("part touched :",part.Name)
wait(1)
print("destroyed")
script.Parent:Destroy()
end
touchConn = script.Parent.PrimaryPart.Touched:Connect(onTouched)
wait(5)
script.Parent:Destroy()