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

Error: Attempt to index local 'player' (a number value)?

ServerScriptService.Leaderboard:17: attempt to index local 'player' (a number value)

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "leaderstats"
	local cash = Instance.new("IntValue",folder)
	cash.Name = "Cash"
	
	cash.Value = ds1:GetAsync(player.UserId) or 0
 	ds1:SetAsync(player.UserId, cash.Value)

   	cash.Changed:Connect(function()
  		ds1:SetAsync(player.UserId, cash.Value)
	end)
	game.ServerStorage.Give.Event:Connect(function(player,Amount)
  		if player.Name == player.Name then
			cash.Value = cash.Value + Amount
		end
	end)
end)

Filtering Enabled on

Script in ServerScriptService

BindableEvent in ServerStorage

BindableEvent rename to Give

I do it a lots of time but it not work.

I script 2 script

1.leaderboard 2.kill for money script

It not give me the Cash when I kill NPC.

I open output and click the only error one.

and it go to the box up there.

Please help.

1 answer

✓ Accepted answer

#Issues There are a few issues with your code.

###Firstly, you are obviously not parsing the correct arguments. If the script believes that the player is the number, then you obviously have not passed the player as an argument to the event.

###Secondly, the event overrides the player variable in the script, meaning the if statement will always return true, and every person will always receive the cash. Rename the variable on the event arguments to something else to fix this.

#Conclusion So, you just need to check your script which fires the event and rename a variable, and hopefully everything should be working.

If I helped you, remember to mark this as the correct answer and thumbs up. :)

2 comments

0

Thank, it work but there is a second error but I will not delete this

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