Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:28pm
#1
Heya! I’m trying to create an easily customizeable potion purchasing system where you enter the details of a potion and it creates a template where you can purchase it.
it creates the template but i cant buy it. There are no errors
Please help, thanks!
Module Script (RepStorage):
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()
script.Parent.PotionPurchase:FireServer()
end)
end
return MerchantHandler
GivePotionOnPurchase script (StarterPlayerScripts)
local mod = require(game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase
Remote.OnClientEvent:Connect(function(Player, purchaseThis)
local statsValue = Player:WaitForChild("Boosts"):FindFirstChild(purchaseThis)
local info = mod.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)
2 Likes
Um if your using a remote event then they don’t work with client to client. I would suggest using a bindable event instead
1 Like
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:37pm
#3
Alr, thanks for the help!
Summary
This text will be hidden
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:41pm
#4
@hya123456h But how? i never used these before
There exactly like remote events but work server - server or client - client.
To send one you can just do BindableEvent:Fire()
then to receive that just do BindableEvent.Event:Connect(function here)
2 Likes
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:45pm
#6
what would i replace that function here with?
1 Like
Exact same as you had before so just
function(Player, purchaseThis)
local statsValue = Player:WaitForChild("Boosts"):FindFirstChild(purchaseThis)
local info = mod.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)
1 Like
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:46pm
#8
Where tho? this is so confusing!
James:
local mod = require(game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase
Remote.OnClientEvent:Connect(function(Player, purchaseThis)
local statsValue = Player:WaitForChild("Boosts"):FindFirstChild(purchaseThis)
local info = mod.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)
On this script just instead of doing Remote.OnClientEvent
do BindableEvent.Event
1 Like
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:49pm
#10
Oh alright lol, but i still dont get what i would put here
Wait never mind omg I am soo sorryy
1 Like
James:
local mod = require(game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase
Remote.OnClientEvent:Connect(function(Player, purchaseThis)
local statsValue = Player:WaitForChild("Boosts"):FindFirstChild(purchaseThis)
local info = mod.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)
This script should be a server script located in server script service.
2 Likes
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:53pm
#13
With the bindable event rework? or the remote event
remote event. Sorry about that
1 Like
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:54pm
#15
I tried that but i kept getting an error message: Requested module failed to load and attempted to index nil with:Waitforchild()
What line does it say the error is occurring at?
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 4:57pm
#18
Line 1 Module script at line 5
Line 2: Server script at line 1
Scxiptifyz
(Scxiptifyz)
January 22, 2024, 5:05pm
#19
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()
script.Parent.PotionPurchase:FireServer(Player, MerchantHandler.Items[name])
end)
end
return MerchantHandler
local mod = require(game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").MerchantHandler)
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Merchant").PotionPurchase
Remote.OnServerEvent:Connect(function(Player, purchaseThis)
local statsValue = Player:WaitForChild("Boosts"):FindFirstChild(purchaseThis)
local info = mod.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)
Ok so I know why it’s erroring but it would be hard to stop it and make it still work
1 Like