Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't the .Touched function working?

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 answer

Correct me if I'm mistaken, but Touched is not a property of Bat, so try something like this:

bat.onTouch:connect...

I am very new to scripting so I'm not too sure but might as well try...

1 comment

0

.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

This discussion is preserved as it was. New answers, comments, and votes are closed.