Error While getting players name to lift a weight with animation

Error is

17:09:23.898 ServerScriptService.Script:6: attempt to index nil with 'Name' - Server - Script:6

Code Is

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClientForWeightLift = ReplicatedStorage:WaitForChild("ClientForWeightLift")

ClientForWeightLift.OnServerEvent:Connect(function(player, Tool)
	local Tool = script.Parent
	local Character = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
	local LiftingAnimation = Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Lifting"))
	
	local Player = game.Players:GetPlayerFromCharacter(Character)

	if Player then
		Player.leaderstats.Strength.Value += 1
		LiftingAnimation:Play()
	end
end)

About What Making

Im making A Weight, that gives strength everytime A player, Activates/Clicks The mouse It'll Give Strength and do an animation.

What Have I Not Finish

I have, not finished my strength leaderstats script.

You can’t use Local player on the server. To get the character, use player.Character

2 Likes

Idk why but I thought that said Line 8

It’s not possible to reference the LocalPlayer in a Server Script, as that’s only possible from Local Scripts

For line 6, did you mean to do

	local Character = game.Workspace:WaitForChild(player.Name)

?

1 Like

Im Doing a Remote Event is it still fine that i put it in workspace?

I’m not exactly sure why you’re referencing the Character variable inside the workspace, when it could be more simplier to just do:

local Character = player.Character

It saves up a bit of extra lines rather than looking for it on the workspace

Yes, i meant Player.Name But in the Player Properties there is something Named, Name.

i just tried that

Error is
17:24:17.147 ServerScriptService.Script:6: attempt to index nil with ‘Character’ - Server - Script:6

Which you just said possible on an Local Script.

Even still, that’s not how you reference it

In your if Player then conditional check, you’re checking if the Player’s Name is a Character Model which wouldn’t be valid to the function itself

I also just realized you’re defining Tool again, even when you referenced the Tool parameter on your OnServerEvent…? Why?

Could you try this at least?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClientForWeightLift = ReplicatedStorage:WaitForChild("ClientForWeightLift")

ClientForWeightLift.OnServerEvent:Connect(function(player, Tool)
	local BaseTool = script.Parent
	local Character = player.Character
	local LiftingAnimation = Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Lifting"))
	
	local leaderstats = player:FindFirstChild("leaderstats")

	if leaderstats then
		Player.leaderstats.Strength.Value += 1
		LiftingAnimation:Play()
	end
end)

Edit: I just realized you’re also re-defining the player, when you could just reference it with the player parameter provided by OnServerEvent

I’ll try and respond back if it works, it’ll be a second.

theres an error 17:27:51.458 Infinite yield possible on ‘ServerScriptService.Script:WaitForChild(“Lifting”)’ - Studio

i think the client does not know what is lifting, which is in the script thats weird…

There’s no Animation called “Lifting” inside the Script in ServerScriptService, are you sure you didn’t move it somewhere else?

o, yeah I placed it somewhere else good look.

It worked thank you so much i appriciate it.