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)
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.
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.
If this is a server script, you cannot use game.Players.LocalPlayer to call the player inside of a server script.
If this is a local script, you cannot use “OnServerEvent”.
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.
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?
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.
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.