I've made a kind of simple script for boats and swimming, but I got stuck with the following problem: I've made a part that checks everything in front of you to make sure that nothing's blocking the way. All of a sudden the .Touched function doesn't seem to react, which causes the collision detection to not work. This is my code, I hope you can help:
local bat = Instance.new("Part", script.Value.Value.Parent)
bat.FormFactor = "Custom"
bat.Transparency = 0
bat.Size = Vector3.new(3, 3, 1)
bat.CFrame = plr.Character.Torso.CFrame*CFrame.new(0, 0, -plr.Character.Torso.Size.Z)
bat.Anchored = true
bat.CanCollide = false
for i = 1, 10 do
bat.CFrame = bat.CFrame*CFrame.new(0, 0, -0.02)
bat.Touched:connect(function(Part)
if Part.Parent ~= bat.Parent then
cw = true
elseif Part.Parent == bat.Parent then
if Part.Name ~= "Water" then
cw = true
end
end
end)
wait()
end
bat:remove()
if cw == false then
plr.Character.Torso.CFrame = plr.Character.Torso.CFrame*CFrame.new(0, 0, -0.2)
end
cw = false
Also the script is a LocalScript.

1 comment
.Touched is the ROBLOX function and onTouch may be some defined function, but the problem of mine is that .Touched isn't being called in LocalScripts