Why wont this work?

like this?

nope in the other server script

1 Like


?

1 Like

no in the server script those are module scripts

1 Like

image

1 Like

ok so it is working all that is wrong is the purchaseThis parameter. Try printing that out

1 Like

It prints out the same thing as the previous one

Ok so when firing the server don’t include the player parameter it automatically gets sent through

1 Like

But what about


and the others

Those are fine just leave that there it only when firing you only send 1 parameter

1 Like


Server storage

Let’s see all your scripts now

1 Like

ServerStorage:


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")},

	}
	
	print(Items)

	return Items
end


return MerchantHandler

Replicated

local MerchantHandler = {}

local Player = game:GetService("Players").LocalPlayer

local LeaderstatsFolder = Player:WaitForChild("leaderstats")
local BoostsFolder = Player:WaitForChild("Boosts")

MerchantHandler.PotionPurchaseCooldown = 3600 -- (3600 = 1 Hour),  (86400 = 1 Day)

MerchantHandler.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")},

}

function MerchantHandler.CreatePotionPurchaseFrame(name)
	local Template = script.Parent:WaitForChild("Potion1"):Clone()
	local gui = Player.PlayerGui:WaitForChild("Main"):WaitForChild("PotionMerchant")

	Template.Name = MerchantHandler.Items[name].Title
	Template.Icon.Image = MerchantHandler.Items[name].Image
	Template.PotionName.Text = MerchantHandler.Items[name].Title
	Template.Purchased.Text = MerchantHandler.Items[name].Purchased.."/"..MerchantHandler.Items[name].MaxPurchase
	Template.PriceLabel.Text = MerchantHandler.Items[name].Price.." "..MerchantHandler.Items[name].Currency.Name

	Template.Parent = gui:WaitForChild("Main"):WaitForChild("Container")

	Template.BuyButton.Button.MouseButton1Click:Connect(function()
		game.ReplicatedStorage:WaitForChild("Merchant").PotionPurchase:FireServer(MerchantHandler.Items[name])
	end)


end

return MerchantHandler

Serverscript

local mod = require(game:GetService("ServerStorage").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase


Remote.OnServerEvent:Connect(function(purchaseThis, Player)
	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")[info[purchaseThis].Currency.Value]

	if currency >= price then
		currency -= price
		statsValue.Value += info[purchaseThis].Time
	end
end)
1 Like

Don’t switch them round… Player will always be the first received parameter on a server event. Then it is all the other parameters you passed through

1 Like

Made another post which is clearer. try post on there if you can lol

Ok well this script should work

local mod = require(game:GetService("ServerStorage").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")[info[purchaseThis].Currency.Value]

	if currency >= price then
		currency -= price
		statsValue.Value += info[purchaseThis].Time
	end
end)



1 Like

2 things:

  1. Error:

  1. The serverstorage script is a pain. I have to update THAT aswell to make a new potion displayed. Not what im going for. Is there a work around?

Sorry can’t talk for any longer. But you could try just putting all the info in the first module script but leave out the bit where you try and get the values then when you need the table you can check in that script for the value of it using the name

1 Like