Problem with index in nil

attempt to index nil with ‘Connect’

Hit.Touched:Connect(function(Toucher)
if Toucher.Name == “Grass” then
Hit.RotVelocity = Hit.RotVelocity * 0.1
end
end)
thats the script

  1. What do you want to achieve? That if the ball touches the grass the RotVelocity of the ball is doubled by 0.1

Could we get some context? What is Hit? Is it a variable?

i believe you are saying that hit is part and there is rotvelcity inside the part and you want to change it, each time anyone who hits it ?

Hit is a variable from another function

Could you post the full script?

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) -]]

Could you post the full script? I can’t tell you what’s wrong without it as that’s likely part of the problem.

Dude the script have over 100 lines

That’s fine. You should still post it. Maybe hide it with the hide details option though.

Screen Shot 2020-06-11 at 2.38.46 PM

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

First off, change :connect to :Connect as the one with the lowercase c is deprecated and shouldn’t be used anymore.

Next, try assigning Hit to a global variable. Something like this should work:
hitBlock = Hit

And then use hitBlock as your variable in the other function instead of Hit.

I’ll try using Hitbox (30chars)

I did and its the same error
(30chars)

Might be because your function is commented out.

can you explain it further?

(30chars)

1 Like

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.

Hit is the ball, and it works correctly for the other arguments of the same function in which it exists

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.

1 Like

Maybe you should try debugging with prints.

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

“Grass” It is a part and this when touched makes the RotVelocity of the ball go fencing doubling

1 Like