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

how do I fix "Players.AM910SK.Backpack.Rasengan.Damage:12: attempt to index nil with 'Character'"?

Asked by
AM910sk 22
5 years ago

I have a damage script inside my tool that uses body velocity to blowback anyone who gets hit by it but it keeps saying that Character is a nil value.

This is a normal script inside my tool

script:

01local player = game.Players.LocalPlayer
02local handle = script.Parent.Handle
03local debounce = false
04 
05handle.Touched:Connect(function(hit)
06    if not debounce and hit.Parent.Humanoid then
07        debounce = true
08        hit.Parent.Humanoid:TakeDamage(50)
09        local bv = Instance.new("BodyVelocity")
10        bv.Parent = hit.Parent.Humanoid
11        bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
12        bv.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 50
13        bv:Destroy()
14        wait(3)
15        debounce = false
16    end
17end)
0
You can't get player like that in normal script, use local instead karlo_tr10 1233 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Usually this is because the character hasn't loaded, but it seems this is not within a LocalScript. In order to use LocalPlayer, you require a LocalScript, not a normal script. You can use a LocalScript and RemoteEvents to use a normal script instead, if you want, though.

Ad

Answer this question