Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't the .Touched function working?

Asked by
Wutras 294 Moderation Voter
9 years ago

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:

01local bat = Instance.new("Part", script.Value.Value.Parent)
02                bat.FormFactor = "Custom"
03                bat.Transparency = 0
04                bat.Size = Vector3.new(3, 3, 1)
05                bat.CFrame = plr.Character.Torso.CFrame*CFrame.new(0, 0, -plr.Character.Torso.Size.Z)
06                bat.Anchored = true
07                bat.CanCollide = false
08                for i = 1, 10 do
09                    bat.CFrame = bat.CFrame*CFrame.new(0, 0, -0.02)
10                    bat.Touched:connect(function(Part)
11                        if Part.Parent ~= bat.Parent then
12                            cw = true
13                        elseif Part.Parent == bat.Parent then
14                            if Part.Name ~= "Water" then
15                                cw = true
View all 25 lines...

Also the script is a LocalScript.

1 answer

Log in to vote
0
Answered by 9 years ago

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

1bat.onTouch:connect...

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

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 Wutras 294 — 9y
Ad

Answer this question