所以我想这样做,所以当我点击它时,它会给我一个"硬币;但它不起作用&表示尝试使用"排行榜"索引为零
`game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = 'leaderstats'
local coins = Instance.new('IntValue', leaderstats)
coins.Name = 'Coins'
coins.Value = 0
end)
game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function()
local currency = 'Coins'
local amount = 5
player.leaderstats[currency].Value = player.leaderstats[currency].Value + amount
end)``
您忘记了"玩家";OnServerEvent中的参数,这就是它为nil 的原因
修复:
game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function(player) --added player parameter
local currency = 'Coins'
local amount = 5
player.leaderstats[currency].Value = player.leaderstats[currency].Value + amount
end)