Why is there an error? I know its to do with the client side. What if i used remote functions
Error is because you can’t access the local player when a module script is required by a server script because then it basically runs as a server script.
Ooh, so what if i change it back to a local script?
won’t save or do anything as only affecting that player
Hello? are you there.
type or paste code here
yes
type or paste code here
Have you thought of a solution yet?
So maybe make a seperate one inside of server storage and in that one do
local MerchantHandler = {}
function MerchantHandler.GetItems(Player)
local LeaderstatsFolder = Player:WaitForChild("leaderstats")
local BoostsFolder = Player:WaitForChild("Boosts")
local Items = {
["Potion1"] = {Potion = BoostsFolder["Gem Potion"].Value, Time = 30, Image = "rbxassetid://15434984615", Title = "Gem Potion", MaxPurchase = 1, Purchased = 0, Price = 12, Currency = LeaderstatsFolder:WaitForChild("Taps")},
["Potion2"] = {Potion = BoostsFolder["Super Lucky"].Value, Time = 60, Image = "rbxassetid://15434984615", Title = "Super Luck Potion", MaxPurchase = 2, Purchased = 0, Price = 24, Currency = LeaderstatsFolder:WaitForChild("Taps")},
["Potion3"] = {Potion = BoostsFolder["Extra Lucky"].Value, Time = 90, Image = "rbxassetid://15434984615", Title = "Luck Potion", MaxPurchase = 3, Purchased = 0, Price = 36, Currency = LeaderstatsFolder:WaitForChild("Taps")},
}
return Items
end
return MerchantHandler
Then in the server script you can do
local mod = require(game:GetService("ServerStorage"):FindFirstChild("Merchant").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase
Remote.OnServerEvent:Connect(function(Player, purchaseThis)
local Items = mod.GetItems(Player)
local statsValue = Player:WaitForChild("Boosts"):FindFirstChild(purchaseThis)
local info = Items[purchaseThis]
if not statsValue or not info then warn("No Boost or info") end
local price = info[purchaseThis].Price
local currency = Player:WaitForChild("leaderstats"):FindFirstChild(info[purchaseThis].Currency.Value)
if currency >= price then
currency -= price
statsValue.Value += info[purchaseThis].Time
end
end)
When i press the button in the serverstorage i get attempted to inex nil with waitforchild
line 5 local LeaderstatsFolder = player:WaitForChild(“leaderstats”)
oops I fixed it now
type or paste code here
ServerScriptService.Extra.PotionMerchant:10: attempt to index nil with Instance
local price = info[purchaseThis].Price
get it to print out the info then for debugging
I get the error: No Boost Found
Oh I know why. Ok forgot a capital letter so retry code above again
I still get the same error, i fixed the capitals before
Ok then see what it does when you print out the items
“No Boosts found”
type or paste code here
no as in when you print this variable out local Items = mod.GetItems(Player)
I did but it came up with that error.
When i click the gui this is what comes up
EDIT: Sorry for late responses btw, been playing roblox with some friends but im done now lol
Yes that would happen but what is the output if you add in
print(Items)