17:31:22.864 - Value is not a valid member of Folder This error comes up for both ServerScript and local script
Local script
local replicatedStorage = game:GetService("ReplicatedStorage")--Defines replicated storage
local selectedItem = script.Parent.Parent.Parent:WaitForChild("SelectedItem")--Defines what selectedItem is
local success--Variable
script.Parent.MouseButton1Click:Connect(function()
success = false--Makes success false
if selectedItem.Value ~= nil then--If the value isn't equal to nil
selectedItem.Value = script.Parent.Parent.Name
print(selectedItem.Value)
success = replicatedStorage.CheckSale:InvokeServer(selectedItem.Value)--Make a request to the remote function
end
if success then
print("Purchased!")
else
print("Purchase Failed!")
end
end)
ServerScript
local replicatedStorage = game:GetService("ReplicatedStorage")--Defines replicated storage
local shopItems = game:GetService("ServerStorage"):WaitForChild("ShopItems")--Defines the items in ServerStorage
replicatedStorage.CheckSale.OnServerInvoke = (function(player,item)--Responds to the remote function request
local price = shopItems[item].Value.Value--Defines the price of the item
if player.leaderstats.Value.Value >= price then--Check to see if the player has enough money
player.leaderstats.Points.Value = player.leaderstats.Points.Value - price--Subtracts the price
local gear = shopItems[item[item]]:Clone()--Clones the item they bought
gear.Parent = player.Backpack--Put the clone in their backpack
return true
else
return false
end
end)
So I noticed you said that same error comes up for both server and client?? Is that suggesting (selectedItem) isn’t a value but a folder? I’m unsure about some of this context so maybe send a image of all the client and server depends on to run your code and I’ll have a better understanding.
Edit: To make sure maybe have a test print along the lines of
To fix it for client, he’d have to change it from .Value to :FindFirstChild(“Value”) in the if statement where he is checking if Value is nil or not.
local data_store_name = "NoPeeking" -- never share your datastore name with ANYONE!
local ds = game:GetService("DataStoreService"):GetDataStore(data_store_name)
local function join(plr)
-- leaderstats script
-- Do NOT add this part if you already have a leaderstat script!
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
local elixir = Instance.new("IntValue")
elixir.Name = "Elixir"
elixir.Value = 0
elixir.Parent = leaderstats
local darkElixir = Instance.new("IntValue")
darkElixir.Name = "Dark Elixir"
darkElixir.Value = 0
darkElixir.Parent = leaderstats
-- Add this part no mater what!
local data1
local data2
local data3
local suc, err = pcall(function()
-- you can add more if you ever want to
data1 = ds:GetAsync(plr.UserId.."_gold")
data2 = ds:GetAsync(plr.UserId.."_elixir")
data3 = ds:GetAsync(plr.UserId.."_darkElixir")
end)
if suc then
plr.leaderstats.Gold.Value = data1
plr.leaderstats.Elixir.Value = data2
plr.leaderstats:FindFirstChild("Dark Elixir").Value = data3
else
warn("Couldn't get ".. plr.Name .. "'s data.\n", err)
end
end
local function leave(plr)
local suc, err = pcall(function()
-- If you added any extra values at top, remember to add them here!
ds:SetAsync(plr.UserId.."_gold", plr.leaderstats.Gold.Value)
ds:SetAsync(plr.UserId.."_elixir", plr.leaderstats.Elixir.Value)
ds:SetAsync(plr.UserId.."_darkElixir", plr.leaderstats:FindFirstChild("Dark Elixir").Value)
end)
if not suc then
warn("Couldn't save ".. plr.Name.."'s data.\n".. err)
end
end
game.Players.PlayerAdded:Connect(join)
game.Players.PlayerRemoving:Connect(leave)
I changed points to gold so can I substitute it like this?