#Each 1000 studs you get 10 cash, but the 14 line cant index nil with leaderstats, please help me!

78 messages · Page 1 of 1 (latest)

plucky bear
#

Its a driving system so each 1000 studs you will get 10 cash, in the script it has a int value when the intvalue hits 1000(studs) it should give 10 cash, the the error pops up

cunning relic
#

since getting the player is conditional

daring bluff
#

Player only gets declared on the touched event. Yet the while loop will run before that

plucky bear
#

oh

#

so i put the while true do section before the ends?

cunning relic
#

Just check if there's a player

plucky bear
#

Right

#

there is a player

#

i can confirm that

cunning relic
#

What 🤣

#

I meant put a if statement in the while loop to check if there's a player

plucky bear
#

oh lol

#

right

#

im dumb

cunning relic
#

Its fine lmao

plucky bear
#

"if while true do then", like that?

cunning relic
#

no

sage forge
#

if player then
-- stuff
else
print("plr notloaded")
end

cunning relic
#

dont even need else but yeah

sage forge
cunning relic
#

also if u wanna make ur code shorter u can do player.leaderstats.Cash.Value += 10 instead of player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10

#

no difference, just more readable imo

plucky bear
#

Alright

floral charm
#

remembering that you need to declare the leaderstats before calling it I think

daring bluff
plucky bear
#

Do i put if player then instead of while true do

cunning relic
teal jungleBOT
#

studio** You are now Level 3! **studio

cunning relic
#

etc

plucky bear
#

ight thank you dude

#

dang

#

now this happens

#

when i do that

daring bluff
#

Did you add a wait in the while true loop?

#

If not then that’s your issue

plucky bear
#

between while true loop and if player?

cunning relic
plucky bear
#

yeah i've done that

cunning relic
#

and still getting the error?

plucky bear
cunning relic
#

you can remove the second wait

#

but yeah should work now

plucky bear
#

right

cunning relic
#

and wait

#

no

plucky bear
#

huh

cunning relic
#

not sure if it works in lua but

#

u might have to indent the code after if player then

#

haven't been coding on roblox for long

plucky bear
#

oh yeah

cunning relic
#

so not sure

plucky bear
#

nothing happens

#

you're right

#

the int value doesn

#

count

#

neither i get the money

#

or miles

cunning relic
#

the if statement is only preventing the error, it's not grabbing the player for you

plucky bear
#

yeah

cunning relic
#

atm the only way to grab the parent is by touching that part or w/e

#

u can use a few print statements to find out where the program aint working

plucky bear
#

nobody really neither posts about drive to get cash on the roblox studio page

cunning relic
#

is this your first game?

plucky bear
#

oh no no

#

i've been on for like 3 years

#

i do gui and icons and thumbnails

#

that

#

im not the best at scripting

cunning relic
#

ay me neither dw

plucky bear
#

lol

cunning relic
#

but yeah, print out player, metersdriven.value and script.parent.velocity.magnitude

#

u should be able to figure out on ur own from here but ping me if u cant

plucky bear
#

ight

plucky bear
#

fixed it