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

ServerScriptService.Script:21: attempt to index a nil value?

Asked by 6 years ago

I'm currently getting a problem in my script where a BodyVelocity gets a direction and everything and it works fine when no in a server. But in a server it doesn't work. The error is apparently on the line where i determine the direction a blast should go. This code is inside a server script.

Script:

local BV = Instance.new("BodyVelocity")
    BV.Parent = Blast
    BV.maxForce = Vector3.new(math.huge, math.huge, math.huge)
    local direction = -(Blast.Position - player:GetMouse().Hit.p)
    BV.Velocity = direction.unit * 80

Any help?

0
does unit exists? ILikeTofuuJoe 1 — 6y
0
.unit is a vector3 thing, that line is perfectly valid, possibly `Blast` is nil, try using print to see what all your variables are, one of them must be nil, and then you can do further debugging from there. theCJarmy7 1293 — 6y
0
I think the variable blast is nil Wafflecow321 457 — 6y
0
Which line is line 21 UnityAlex 36 — 6y
View all comments (2 more)
0
line 21 is local direction Wolf5429 15 — 6y
0
@theCJarmy7 I thought that Blast may be nil as well so I went and did player.Character.Blast.Position instead and it still didn't work. Wolf5429 15 — 6y

Answer this question