-
What do I want to achieve? I want to have a proper buy button
-
What is the issue? It is showing this error
itzmerose_12 is not a valid member of Folder "ServerStorage.OwnedItems"
- What solutions have you tried so far? I looked it in youtube and searched in dev forum
--Server side
local rep = game:GetService("ReplicatedStorage")
local items = game:GetService("ServerStorage"):WaitForChild("Tools")
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name ="leaderstats"
stats.Parent = player
local Strength = Instance.new("NumberValue")
Strength.Name ="Strength"
Strength.Parent = stats
local Coins = Instance.new("NumberValue")
Coins.Name ="Coins"
Coins.Parent = stats
Coins.Value = 49
local gems = Instance.new("NumberValue", stats)
gems.Name = "Gems"
local storage = Instance.new("NumberValue")
storage.Value = 10
storage.Name = "Storage"
storage.Parent = player
local Class = Instance.new("StringValue")
Class.Name = "Class"
Class.Parent = stats
local items = Instance.new("Folder", player)
items.Name = "OwnedItems"
end)
rep.Remotes.info.OnServerInvoke = function(player , item)
return items[item].Cost.Value
end
game:GetService("ReplicatedStorage").Remotes.sale.OnServerInvoke = function(player , item)
local playergui = player.PlayerGui
print(player.Name.."Invoked server")
price = items[item].Cost.Value
if player.leaderstats.Coins.Value >= price and not game.ServerStorage.OwnedItems[player.Name]:FindFirstChild(item)then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - price
player.Character.Humanoid:UnequipTools()
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool.Name == player.Equipped.Value then
tool:Destroy()
end
endl
player.Equipped.Value = item
local gear = items[item]:Clone()
gear.Parent = game.ServerStorage.OwnedItems
local gear = items[item]:Clone()
gear.Parent = player.Backpack
return true
elseif price > player.leaderstats.Coins.Value and not game.ServerStorage.OwnedItems[player.Name]:FindFirstChild(item) then
return "Not enough"
else
return "Bought already"
end
end
game.ReplicatedStorage.Remotes.toolbought.OnServerInvoke = function(player, item)
local tools = {}
for i,tool in pairs(game.ServerStorage.OwnedItems[player.Name]:GetChildren()) do
table.insert(tools, tool.Name)
end
return tools
end
--Client side
local rep = game:GetService("ReplicatedStorage")
local itemsel = script.Parent.Parent.selecter
local selecter = script.Parent.Parent.selecter
local cantbuy = script.Parent.Parent.cant_buy
local status = script.Parent.Parent.status
local outcome = rep.Remotes.sale:InvokeServer(selecter.Value)
script.Parent.MouseButton1Click:Connect(function()
local outcome = rep.Remotes.sale:InvokeServer(selecter.Value)
if outcome == true then
status.Text = "Equipped"
elseif outcome == "not enough" then
print("YEET")
elseif outcome == "Bought already" then
if game.Players.LocalPlayer.Equipped.Value ~= selecter.Value then
game.ReplicatedStorage.Remotes.EquipTool:FireServer(selecter.Value)
status.Text = "Equipped"
end
end
end)
selecter:GetPropertyChangedSignal("Value"):Connect(function()
local model = selecter.Value
local toolsbought = game.ReplicatedStorage.Remotes.toolbought:InvokeServer()
for i, tool in pairs(toolsbought) do
if tool == model.Name then
status.Text = "Equipped"
else
status.Text = "Equip"
end
end
end)
Please help ASAP thank you!
