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
8 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:

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

Log in to vote
0
Answered by 8 years ago

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...

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 — 8y
Ad

Answer this question