I want to change strength to cash when i touched a brick in the leader board,after making somethings,i have an error in the brick's script(not local script), its said index nil with leaderstats.Here i have 2 scripts:1 at sever script service:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
local strength = Instance.new("IntValue")
strength.Value = 0
strength.Parent = leaderstats
strength.Name = "Strength"
end)
1 at the brick(Where have that error):
local player = game.Players.LocalPlayer
local leaderstats = player.leaderstats
local strength = leaderstats.Strength
local cash = leaderstats.Cash
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
cash.Value = cash.Value + strength.Value
end
end)
Please help me if you can.
Edit:change script to local script will not work,even there is no error.

3 comments
You are not getting the leaderstats properly in a serverscript and it needs to be a 'script' not a local script since they only run on the client
Check my answer
I have used a script already, but it doesn't work