Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to index nil to 'Name' can you help me? Its for a weight lifting simulator.

Asked by 4 years ago

I'm very new to coding and I'm very confused on why my code wont work. In the output section it says attempt to index nil to 'Name' can someone just make something can just copy and paste in please? Here is the code:

local player = game.Players.LocalPlayer local replicatedStorage = game:GetService("ReplicatedStorage")

local remoteData =game:GetService("ServerStorage"):WaitForChild("RemoteData") local starterRebirthAmount = 5000

local cooldown = 1

replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)

01if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
02 
03local debounce = remoteData[player.Name].Debounce
04if not debounce.Value then
05 
06    debounce.Value = true
07 
08    player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 10 * (player.leaderstats.Rebirths.Value + 1)
09 
10    wait(cooldown)
11 
12    debounce.Value = false
13 
14end

end)

replicatedStorage.Remotes.Rebirth.OnServerInvoke = function()

01if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
02 
03local rebirths = player.leaderstats.Rebirths
04 
05if player.leaderstats.Strength.Value >= (math.floor((starterRebirthAmount + (rebirths.Value * math.sqrt(5000000))))) then
06 
07    rebirths.Value = rebirths.Value + 1
08 
09    player.leaderstats.Strength.Value = 0
10 
11    player:LoadCharacter()
12 
13     return true
14    else return "NotEnoughStrength"
15end

end

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

The problem I see in most ServerScripts is that people do not know when to use the LocalPlayer instance. You can only use them in local scripts, which are on the client side. I'm assuming you are using a ServerScript.

How you could get a player, is that using the PlayerAdded event to your advantage.

Here is an example:

1game.Players.PlayerAdded:Connect(function(player) --player parameter used here
2--put code here
3end)

You can replace your player variable with the parameter, and there you have your answer!

Ad

Answer this question