Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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:

local player = game.Players.LocalPlayer
local handle = script.Parent.Handle
local debounce = false

handle.Touched:Connect(function(hit)
	if not debounce and hit.Parent.Humanoid then
		debounce = true
		hit.Parent.Humanoid:TakeDamage(50)
		local bv = Instance.new("BodyVelocity")
		bv.Parent = hit.Parent.Humanoid
		bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		bv.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 50
		bv:Destroy()
		wait(3)
		debounce = false
	end
end)

1 comment

0

You can't get player like that in normal script, use local instead

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.