My Strength Increase script is getting index nil 'name'

Hi, I am making a statshandler for my weight lifting simulator but I’m always getting index nil on my script at plr.name. I’ve tried FindFirstChild and game.Players.Playersadded but none of them worked. Anybody have a fix? Script is down below.

local stats= game.ServerStorage.PlrFolder
local ls= game.Players:FindFirstChild("leaderstats")
local remoteEvent= game.ReplicatedStorage.addStrength
local plr = game.Players.LocalPlayer
local gps= game:GetService("GamePassService")
local weightID= 984529526
local mps= game:GetService("MarketplaceService")
local steroidId= 92869550
local saladId= 92869747
local thePlr

if stats:FindFirstChild(plr.Name) == nil then
		local pf= script.plr:clone()
		pf.Parent=stats
		pf.Name= plr.Name
		pf.Size.Value= 0.2
		pf.Speed.Value=15
	end

remoteEvent.OnServerEvent:Connect(function(plr, handle, amount)
	if amount > 100 then
		plr:Kick("Nice Try Hacker")
	elseif amount < 100 then
		local pf= stats:FindFirstChild(plr.Name)

		wait()
		
		local h= plr.Character.Humanoid
			pf.Num.Value=pf.Num.Value+1
			print(handle)

		for i = 1,pf.Num.Value, 1 do
			if i == 5 then i = 0
					ls.Strength.Value= ls.Strength.Value+1
				if amount > 1 then
					ls.Strength.Value= ls.Strength.Value+4
					pf.Durability.Value= pf.Durability.Value+20
				end
				
				local sound= Instance.new("Sound")
				game.Debris:AddItem(sound, 3)
				sound.Parent= plr.Character.LowerTorso
				sound.SoundId= "rbxassetid://565208983"
				sound.Volume=0.4
				sound:Play()
			end
		end
	
	wait()	
				
		end
	end)
2 Likes

Is this a script on the client or in the server? If its on the client. Your remote event connection is wrong and needs to be changed according to your script.

remoteEvent.OnServerEvent

If this script on the server, then you cannot get the local player on the server because there is no local player but instead all the players.

local plr = game.Players.LocalPlayer

No its on serverscriptservice so I think its serversided.

  1. The 2nd line shows you’re looking for a folder called “leaderstats” inside of Players, which doesn’t make sense if you have a leaderstats folder inside of Players.

  2. If this is a server script, you cannot use game.Players.LocalPlayer to call the player inside of a server script.

  3. If this is a local script, you cannot use “OnServerEvent”.

the script is a normal script inside of serverscriptservice and it says leaderstats is not a vaild member of players

If it is a normal script, you cannot use game.Players.LocalPlayer

Edit: Also, you cannot do game.Players:FindFirstChild(“leaderstats”) because you are referencing all the players.

oh then how would I define the variable for leaderstats

Alright first give me a rundown on what you are trying to accomplish overall.

I’m trying to accomplish an advanced strength handler. I might sound like a complete noob but I cant figure out on how to define a leaderstats variable for a normal script.

Okay well to define a player in a normal script for your case use the player parameter.

What line does it show the error on?

stats:Findfirstchild(plr.name) the error only happens when I add the leaderstats variable.

1 Like

Ok I recommend doing this. This is a very long method but it might just work for you.

Edit: This is to get the stats of the player.

function getStats(player)
player.leaderstats
end

local stats = getStats()

If the code is failing to index the Name property of the Instance it means that the Instance does not exist. Are you sure you reference the player correctly? If that, is your script a ServerScript or a LocalScript?

My script is on serverscriptservice as a normal script.

1 Like

Well, you simply can not reference LocalPlayer from a ServerScript. You can send the data using RemotEvents from a LocalScript to the ServerScript.

oh I did that from the weight tool but thats just to say that someone clicked the weight and the strengthhandler job is to add the strength to the leaderstat.

1 Like

You tried to index the LocalPlayer in a ServerScript. It is impossible.

I thought you can put local player in any script.

1 Like

Well, only from LocalScripts. I suggest sending the LocalPlayer argument to the ServerScript through the RemoteEvent and then continue with what you meant. If I am not clear enough,
this page might clarify it more simply.