#I NEED HELP

1 messages · Page 1 of 1 (latest)

left sierra
#

my script get this error: "ReplicatedStorage.UI.CatShopData:13: attempt to index nil with 'Price'"

and this is the script that gets the error: ``` local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local CatsHandler = require(ReplicatedStorage.Systems.CatsHandler)
local CatsStats = require(ReplicatedStorage.Assets.Cats.CatStats)

local Frame = script.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
CatsHandler:PurchaseCat(CatsStats[Frame.Name], CatsStats[Frame.Name].Price)
end) ```

#

I NEED HELP

sleek swallow
#

hello

left sierra
#

hi

sleek swallow
#

can you make sure, this line: CatsStats[Frame.Name].Price is exactly how it's supposed to be?

left sierra
#

i can show catsstats if you want

#

return {
["smol cat"] = {
Price = 20,
MoneyPerClick = 0.1,
},

["Bengal"] = {
    Price = 100,
    MoneyPerClick = .5,
},

["Siamese"] = {
    Price = 500,
    MoneyPerClick = 1,
},

["Persian"] = {
    Price = 5000,
    MoneyPerClick = 5,
},

}

#

and its supposded to get the cat based on the frame that the script should be parented to

left sierra
sleek swallow
#

I got a question

#

these are module scripts right?

#

or not?

left sierra
#

the first scipt is a local script

sleek swallow
#

because when it comes to scripting like this I'm not the best

left sierra
#

the catsstats is a module script

sleek swallow
#

ah ok

left sierra
#

me neither

sleek swallow
#

yes I an tell

#

can*

#

I just have one question

left sierra
#

yes

mental fulcrumBOT
#

studio** You are now Level 4! **studio

sleek swallow
#

the script is saying CatStats Frame.name doesn't exist

finite current
#

(moneys per click per price point)

left sierra
#

how can i do that`?

finite current
sleek swallow
#

yeah what pyro said could probably be it

minor pelican
#

add a nil check

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local CatsHandler = require(ReplicatedStorage.Systems.CatsHandler)
local CatsStats = require(ReplicatedStorage.Assets.Cats.CatStats)
local Frame = script.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
    local catData = CatsStats[Frame.Name]
    if catData then
        CatsHandler:PurchaseCat(catData, catData.Price)
    end
end)

something like this

finite current
#

variables are your friend

sleek swallow
#

why not use prints and check its parents.. name, if it even exists where it's supposed to be

finite current
#

catName = Frame.Name print(catName)

sleek swallow
#

exactly

left sierra
#

so i should use varibles more

sleek swallow
#

yes

#

you should REALLY do that

#

don't always stick to long chains

#

most bugs and errors come from those

#

well atleast for me in that case

finite current
sleek swallow
#

XD

left sierra
#

idk really know anythhing about performance stuff

sleek swallow
#

same here

left sierra
#

i dont*

finite current
#

let's make something run optimally which doesn't even run in the first place! now there's an idea fingerguns

sleek swallow
#

but Im guessing more lines ruin performance maybe?

finite current
#

no

#

just ignore performance pretty much entirely. I am a professhonal

sleek swallow
#

👍

left sierra
#

btw pyro how did you learn scripting cuz i cant find anything to learn scripting with

sleek swallow
#

wait then I had a question

finite current
#

its funny but i'm actually not joking.

  1. Make it work
  2. Make it right (do things properly)
  3. Make it fast (optimize)
    in that order.
sleek swallow
#

don't use A.I

finite current
sleek swallow
#

I spent the first year and a half using a.i to barley build a game

left sierra
#

i dont use ai i just get the assisant recommandtations which i sometimes use

finite current
#

or if i do use someone else's work, you can be damn sure i read the code i'm using.

sleek swallow
#

I got a question

#

is there a way to check many things at once? without for loops?

#

like many values at once

finite current
#

wot

sleek swallow
#

yeah

finite current
#

for loop or checksum comparison?

sleek swallow
#

with one line of code

#

I just need to check many values at once

finite current
#

technically you can hide the for loop in a metamethod and do a==b hehe that's one line 😎

sleek swallow
#

what's that

#

I don't really get it

#

a==b?

finite current
#

make a function that checks your many values at once and then your one line of code is calling that function hehe

sleek swallow
#

you mean like a huge if statement

#

in a function?

finite current
#

idk what you're checking, besides, get your own help thread dont hijack theirs

sleek swallow
#

XD ig your right

#

but ty for the function idea, ima do that rn

#

anyway bye