How do i not index nil with character

local player = nil

local Enabled = true

local Animation = nil

local plr = game.Players.LocalPlayer

local char = plr.Character

local HRP = char:WaitForChild(“HumanoidRootPart”)

script.Parent.Equipped:Connect(function()

player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

Animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Animation)

HRP.Parent.Humanoid.JumpHeight = 0

HRP.Parent.Humanoid.WalkSpeed = 0

wait(2)

HRP.Parent.Humanoid.JumpHeight = 7.2

HRP.Parent.Humanoid.WalkSpeed = 16

end)

script.Parent.Activated:Connect(function()

if Enabled == true then

Animation:Play()

player.leaderstats.Strength.Value += script.Parent.Strength.Value

Enabled = false

wait(script.Parent.Cooldown.Value)

Enabled = true

end

end)

You don’t show your explorer view so I guess make sure this is a LocalScript in your Tool and not a regular Script.

game.Players.LocalPlayer only works for LocalScripts and is a reference to the current client running the script but the server isn’t a client and thus the variable LocalPlayer there is nil(because the server simply can’t guess which one of the currently connected players you try to reference). If you want to use the player variable on the server(which I assume you do because you change leaderstats values) it depends on the script and the use case. For your use case since this is a script inside a player tool you can reference the player as script.Parent.Parent which will work if the player hasn’t equipped the tool at the moment(because when they equip it the tool is inside their character) but to ensure you fetch it successfully you can use the following function:

function GetPlayerFromTool(tool: Tool): Player?
	--if the tool is unequipped it will be inside the player backpack
	if tool.Parent:IsA("Backpack") then 
		return tool.Parent.Parent 
	--if the tool is equipped it will be inside the player character
	elseif tool.Parent:IsA("Model") then
		return tool.Parent
	--the tool is at a random location that isn't related to a player
	else
		return nil
	end
end

local player = GetPlayerFromTool(script.Parent)
--also remove the local plr line and replace all "plr" with "player"

local player = nil

local Enabled = true

local Animation = nil



local char = script.parent.parent or script.parent

local HRP = char:WaitForChild(“HumanoidRootPart”)

script.Parent.Equipped:Connect(function()

player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

Animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Animation)

HRP.Parent.Humanoid.JumpHeight = 0

HRP.Parent.Humanoid.WalkSpeed = 0

wait(2)

HRP.Parent.Humanoid.JumpHeight = 7.2

HRP.Parent.Humanoid.WalkSpeed = 16

end)

script.Parent.Activated:Connect(function()

if Enabled == true then

Animation:Play()

player.leaderstats.Strength.Value += script.Parent.Strength.Value

Enabled = false

wait(script.Parent.Cooldown.Value)

Enabled = true

end

end)

So it is saying that plr is nil. LocalPlayer only works in a local script so if this is a server script change it to script.parent.parent as that would be the player’s character

Can you try this solution script?

local player = nil
local Enabled = true
local Animation = nil

script.Parent.Equipped:Connect(function()
	player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) or game.Players.LocalPlayer
	
	local char = player.Character or player.CharacterAdded:Wait()
	
	local humanoid = char:FindFirstChildOfClass("Humanoid")
	
	local HRP = char:FindFirstChild("HumanoidRootPart") or humanoid.RootPart
	
	local animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator",humanoid)
	
	Animation = animator:LoadAnimation(script.Animation)
	
	Animation.Priority = Enum.AnimationPriority.Action4
	
	--Other Values
	HRP.Parent.Humanoid.JumpHeight = 0
	HRP.Parent.Humanoid.WalkSpeed = 0
	wait(2)
	HRP.Parent.Humanoid.JumpHeight = 7.2
	HRP.Parent.Humanoid.WalkSpeed = 16
end)

script.Parent.Activated:Connect(function()
	if Enabled == true then
		Animation:Play()
		player.leaderstats.Strength.Value += script.Parent.Strength.Value
		Enabled = false
		wait(script.Parent.Cooldown.Value)
		Enabled = true
	end

end)