#Script doesnt work

1 messages · Page 1 of 1 (latest)

worldly turret
#

i have this ui and i have a module doing this : ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CatStats = require(ReplicatedStorage.Assets.Cats.CatStats)

local CatShopData = {}

function CatShopData:LoadCatShopData(Frame : Frame)
if not Frame then return end

if Frame.Parent == script.Parent then
    local CatName = Frame:FindFirstChild("CatName")
    local Price = Frame:FindFirstChild("Price")
    local MoneyPerClick = Frame:FindFirstChild("MoneyPerClick")
    
    CatName.Text = Frame.Name
    Price.Text = CatStats[Frame.Name].Price .. "$"
    MoneyPerClick.Text = "+" .. CatStats[Frame.Name].MoneyPerClick .. "$ Per Click"
else
    warn("Script is not parent of " .. Frame.Name .. " Frame")
    return CatShopData
end

end

return CatShopData ```

i have a script not a local script doing thjis inside the frame: ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CatShopData = require(ReplicatedStorage.UI.CatShopData)

CatShopData:LoadCatShopData(script.Parent) ```

what is wrong?

#

and btw i get the warning msg in the output

graceful furnace
#

It kinda make no sense at all?
if Frame.Parent == script.Parent then

worldly turret
#

ohhh wait

#

im just dumb

#

i typed the wrong thing

#

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 CatStats = require(ReplicatedStorage.Assets.Cats.CatStats)

local CatShopData = {}

function CatShopData:LoadCatShopData(Frame : Frame)
local CatName = Frame:FindFirstChild("CatName")
local Price = Frame:FindFirstChild("Price")
local MoneyPerClick = Frame:FindFirstChild("MoneyPerClick")

CatName.Text = Frame.Name
Price.Text = CatStats[Frame.Name].Price .. "$"
MoneyPerClick.Text = "+" .. CatStats[Frame.Name].MoneyPerClick .. "$ Per Click"

end

return CatShopData ```

graceful furnace
#

show CatStats modulescript, it saying you don't have CatStats[Frame.Name].Price

worldly turret
#

return {
[1] = {
Name = "Kitty",
Price = 20,
MoneyPerClick = 1,
},
}

#

idk how to theses kind of modules

graceful furnace
#

so it trying to get ["Kitty"].Price

#

and not [1].Price

worldly turret
#

so i should put the name instead of 1?

graceful furnace
#

That would be a way.

worldly turret
#

ok

#

return {
["Kitty"] = {
Price = 20,
MoneyPerClick = 1,
},
}

#

works