Attempt to index with leaderstats

Hey I’m not that good at scripting yet could you help me I have an error saying attempt index nil with leaderstats this is the script:


Check if your Variable if equal to the Player, if its any, it wont work

I’m sorry I don’t understand could you explain it a bit more?

Type player in your script, on the side, it will tell you what the object is, if it says any and not Player, then thats your issue

Plus, where is your script located?

On the side? lol sorry I don’t understand.

its a localscript does that change it? my first time using localscripts

No, LocalScripts fire for the Player, pretty much the Players Client (aka their computer), only you are going to see the changes but nobody else, You change your Items on the Server so that way everyone can see it

Create a RemoteEvent put it inside ReplicatedStorage, Create a Script inside it, and write this:
Lets say the name of it is Rebirths

RemoteEvent's are Events that can be used Globally, It sends data Between Server and Client

OnServerEvent: Script > LocalScript
This Signal can call the Player
Variables: (Var1, Var2, etc)
OnClientEvent: LocalScript > Script
this Signal Cannot Call the Player
Variables: (Player, Var1, Var2, etc)

local Rebirths = script.Parent

Rebirths.OnServerEvent:Connect(function(Player, Amount, Rebirth)

if Amount >= 100  and Rebirth <= 5 then
Amount = 0
Rebirth +=1


Then on the LocalScript:

local Player = game.Players.LocalPlayer
local ls = Player:WaitForChild("leaderstats")


it doesn’t give any error anymore but it also doesn’t give a rebirth when clicked

I recommend Reading through Documenttion or Watching a Video

Official Roblox Documentation on RemoteEvents / RemoteFunctions

Official Documentation

Video’s that might help you understand a bit more
Video I Recommend #1
Video I Recommend #2
Video I Recommend #3

okay thanks, i will click the previous thing as solution as it helped for the error itself

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.