Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

local debounce = remoteData[player.Name].Debounce
if not debounce.Value then
	
	debounce.Value = true
	
	player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 10 * (player.leaderstats.Rebirths.Value + 1)
	
	wait(cooldown)
	
	debounce.Value = false
	
end

end)

replicatedStorage.Remotes.Rebirth.OnServerInvoke = function()

if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

local rebirths = player.leaderstats.Rebirths

if player.leaderstats.Strength.Value >= (math.floor((starterRebirthAmount + (rebirths.Value * math.sqrt(5000000))))) then
	
	rebirths.Value = rebirths.Value + 1
	
	player.leaderstats.Strength.Value = 0
	
	player:LoadCharacter()
	
	 return true
	else return "NotEnoughStrength"
end

end

1 answer

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:

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.