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.
Here you go. Make sure this is a regular script inside the brick.
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + Player.leaderstats.Strength.Value end end)
Hope this helps
For the script at the brick, use a LocalScript instead of a ServerSidedScript.