Ad
Log in to vote
0

Why cant I compare leaderstats with a local script?

Asked by 4 months ago
Edited 4 months ago

I am trying to make a button that you can buy something but only if you have a certain amount of "Deaths"

here's my script:

 if game.leaderstats.Deaths.Value == 1 then 
    game.Workspace.Parent.StarterPlayer.CharacterWalkSpeed = 70
 end

Can you help me?

0
Could not find a specific YT vid lol kickoff127 15 — 4mo
0
Well are you really sure the `leaderstats` are a child of `game`? Spjureeedd 321 — 4mo
0
No no entirely. The script for leaderstats was a model. kickoff127 15 — 4mo
0
Here's what it says: Players.Username.PlayerGui.Shop.ShopFrame.LevelOne.LocalScript:1: attempt to index nil with 'leaderstats' kickoff127 15 — 4mo

1 answer

Log in to vote
0
Answered by 4 months ago
Edited 4 months ago

leaderstats is not a valid member of game, if you have output open, you will see this error the fix for this is to check the player leaderstats if you even have one by doing this (im assuming you already got a player variable for the player trying to buy something)

if player.leaderstats.Deaths.Value == 1 then
--also, doing .Parent on workspace brings you back to game and my guess from your script is, you want to give the player 70 walkspeed, you do it like this
    player.Character.Humanoid.WalkSpeed = 70
end
Ad

Answer this question