I am trying to have a StringValue as the name of the item in ReplicatedStorage. For example, the ItemName value is "Sword" but it says in output that ("itemName is not a valid member of Folder") How can I make this work?
script.Parent.MouseButton1Click:connect(function()
local RS = game:GetService('ReplicatedStorage')
local itemName = script.Parent.ItemName.Value
local item = RS.Weps.itemName
local itemPrice = script.Parent.PriceValue.Value
--local itemPrice = 100
local Player = game.Players.LocalPlayer
local stats = Player:WaitForChild('leaderstats')
if stats.Money.Value >= itemPrice then
print("Item Purchased!")
stats.Money.Value = stats.Money.Value - itemPrice
print("Player has recieved the item!")
local itemCloned = item:Clone()
itemCloned.Parent = Player.Backpack
itemCloned.Parent = Player.StarterPack
end
end)

1 comment
Make sure to use WaitForChild, as things can sometimes take time to load: local item = RS.Weps:WaitForChild("itemName")