it says in the output trying to index nil with leaderstats
Local TycoonNumber = 1
script.Parent.Touched:Connect(function(player) if player.Parent.Owner.Value == 1 then if game.Players.LocalPlayer.leaderstats.Money.Value <= 0 then game.ServerStorage.Buyable_Items.Droppers.Dropper1.Parent = game.Workspace.A end end end)
if it is impossable to fix then please tell
01 | Local TycoonNumber = 1 |
02 |
03 | script.Parent.Touched:Connect( function (hit) -- this is not the player |
04 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if player.Parent.Owner.Value = = 1 then |
06 | if game.Players.LocalPlayer.leaderstats.Money.Value < = 0 then |
07 | game.ServerStorage.Buyable_Items.Droppers.Dropper 1. Parent = game.Workspace.A |
08 | end |
09 | end |
10 | end ) |
Since you are using the Touched
function, which can only be used for server scripts, I'm assuming you're not using a local script. If so, in line 5, you are attempting to access the LocalPlayer
, which you can only access from a local script. That's why it is returning nil. You can use game.Players:GetPlayerFromCharacter()
on the parent of the "player" variable, then access the leaderstats from there.
01 | local TycoonNumber = 1 |
02 |
03 | script.Parent.Touched:Connect( function (player) |
04 | if player.Parent.Owner.Value = = 1 then |
05 | local plr = game.Players:GetPlayerFromCharacter(player.Parent) -- gets the player from the character |
06 | if plr.leaderstats.Money.Value < = 0 then -- NOW YOU CAN ACCESS THE LEADERSTATS |
07 | game.ServerStorage.Buyable_Items.Droppers.Dropper 1. Parent = game.Workspace.A |
08 | end |
09 | end |
10 | end ) |
Hope it helps