The function I send is the parent of another function
local Active = true
- [[Hit.Touched: connect (function (Toucher)
if Toucher.Name == “Grass” and Active == true then
Active = false
Hit.RotVelocity = Hit.RotVelocity * 0.1
end
end) -]]
nction PhysicsModule.BallCurve(Hit,Power,Direction)
local Active = true
–[[Hit.Touched:connect(function(Toucher)
if Toucher.Name == “Grass” and Active == true then
Active = false
Hit.RotVelocity = Hit.RotVelocity * 0.1
end
end)–]]
if Direction == “R” then
local CurveVelocity = Instance.new(“BodyAngularVelocity”)
CurveVelocity.Parent = Hit
CurveVelocity.AngularVelocity = Vector3.new(0, 45, 0) + Torso.CFrame.rightVector
Debris:AddItem(CurveVelocity,0.2)
local CurlingForce = Instance.new(“BodyForce”)
CurlingForce.Parent = Hit
CurlingForce.Name = “Curling”
RunService.Heartbeat:Connect(function()
math.randomseed(tick())
wait()
if Hit.Velocity.Magnitude > 0.1 then
CurlingForce.Force = (CFrame.new(Vector3.new(0, 0, 0), Hit.Velocity) * CFrame.Angles(0, math.rad(-90), 0)).lookVector * Power * 2
if Power > 2 then
Power = Power - 5
else
Power = 0
end
end
end)
CurlingForce:Destroy()
end
if Direction == “L” then
local CurveVelocity = Instance.new(“BodyAngularVelocity”)
CurveVelocity.Parent = Hit
CurveVelocity.AngularVelocity = Vector3.new(0, -45, 0) + - Torso.CFrame.rightVector
Debris:AddItem(CurveVelocity,0.2)
local CurlingForce = Instance.new(“BodyForce”)
CurlingForce.Parent = Hit
CurlingForce.Name = “Curling”
RunService.Heartbeat:Connect(function()
math.randomseed(tick())
wait()
if Hit.Velocity.magnitude > 0.1 then
CurlingForce.Force = (CFrame.new(Vector3.new(0, 0, 0), Hit.Velocity) * CFrame.Angles(0, math.rad(-90), 0)).LookVector * Power * -1 * 2
if Power > 2 then
Power = Power - 5
else
Power = 0
end
end
end)
CurlingForce:Destroy()
end
if Direction == “F” then
if Power ~= 140 then return end
local CurlingForce = Instance.new(“BodyForce”)
local Right = true
local CurvePower = 550
local ShootPower = Power
wait(0.5)
while Hit.Position.Y > 3 do
RunService.Heartbeat:Wait()
if Hit.Velocity.Magnitude > 0.1 then
if Right == true then
Right = false
local RandomForce = math.random(50, 160)
CurlingForce.Force = (CFrame.new(Hit.Position, Hit.Position + Vector3.new(0, 1, 0)) * CFrame.Angles(0, math.rad(RandomForce), 0)).LookVector * CurvePower
wait(0.1)
CurlingForce.Force = Vector3.new(0, 0, 0)
wait(0.4)
else
Right = true
local RandomCurve = math.random(200, 310)
CurlingForce.Force = (CFrame.new(Hit.Position, Hit.Position + Vector3.new(0, 1, 0)) * CFrame.Angles(0, math.rad(RandomCurve), 0)).lookVector * CurvePower
wait(0.1)
CurlingForce.Force = Vector3.new(0, 0, 0)
wait(0.4)
end
end
end
CurlingForce:Destroy()
end
end
Here, you have some double hyphens which makes it comment, which means it won’t be executed.
Also, you probably have your arguments in the wrong order. It says attempt to index :Connect with nil, which, I believe, means Hit does exist, but it doesn’t have the :Connect function.
It’s saying that Touched is nil which means that the Hit cannot be touched and cannot be used with the touched event. If hit is the ball then make sure its assigned as a variable correctly.
Also, you cannot detect the grass like that unless the grass is a part.
Try starting off with something like this. If it is a part, it will print “Part”, if it isn’t a part, then it will print its class if it has the Class property. Otherwise, it won’t print anything:
if Hit:IsA("Part") then
print("Part")
elseif Hit.Class then
print(Hit.Class)
end