My purchase script is not working

I have a script for buying a fushion and it doesn’t work I can only buy 1 fushion and that’s it I don’t know what the problem is help me fix it

1 Like
local RS = game:GetService("ReplicatedStorage")
local ranks = require(game:GetService("ServerStorage").FusionsModule)

local function buy(player)
	local ownedRanks = {}
	local tp = player["TotalPower"]
	for _, rank in pairs(ranks) do
		if rank["Owned"] then
			table.insert(ownedRanks, rank)
		end
	end
	local bestRank = ownedRanks[#ownedRanks]
	local nextRank = ranks["Fusion"..bestRank.rank + 1]
	if nextRank then
		if tp.Value >= nextRank.Price then
			player.Strength.Value = 0
			player.Psp.Value = 0
			player.Endurance.Value = 0
			local newBest = nextRank
			player.leaderstats.Fusion.Value = newBest.Name
			player.BestFusion.FusionMulti.Value = newBest.Multi
		end
	end
end

RS.FusionUp.OnServerEvent:Connect(buy)
1 Like

This script is located in the server script service and is responsible for the purchase

1 Like
local fusions = {}
fusions.Fusion1 = {Name="None", Price=0, Multi=1, Owned= true, rank=1}
fusions.Fusion2 = {Name="Werewolf", Price=500, Multi=2, Owned= false, rank=2}
fusions.Fusion3 = {Name="Minotaur", Price=1000, Multi=4, Owned= false, rank=3}
fusions.Fusion4 = {Name="Dog", Price=5000, Multi=8, Owned= false, rank=4}
fusions.Fusion5 = {Name="Lola", Price=10000, Multi=16, Owned= false, rank=5}
return fusions

And this is a function module in the server storage script

1 Like

Help me fix it, I don’t know what the problem is

1 Like
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Buy = script.Parent.Parent.BuyFusion
local priceLabel = script.Parent.Parent.Cost_Title
local boostLabel = script.Parent.Parent.YourBoost
local yourFusionLabel = script.Parent.Parent.YourClass_Title
local nextBoostLabel = script.Parent.Parent.NextBoostText
local nextFusionTitleLabel = script.Parent.Parent.NextClass_Title
local price2 = script.Parent.Parent.PriceText
local nextFusionLabel = script.Parent.Parent.NextClassName2
local yourfusionname = script.Parent.Parent.ClassNameText

-- Таблицы с данными о фушионах и бустах
local fusionData = {
	{name = "Werewolf", price = 500, boost = 2},
	{name = "Minotaur", price = 1000, boost = 4},
	{name = "Dog", price = 5000, boost = 8},
	{name = "Lola", price = 10000, boost = 16}
}

-- Функция для получения текущего и следующего фушиона
local function getCurrentAndNextFusion(currentFusion)
	for i, fusion in ipairs(fusionData) do
		if fusion.name == currentFusion then
			local nextFusion = fusionData[i + 1]
			return fusion, nextFusion
		end
	end
	return nil, nil
end

-- Начальное значение текущего фушиона
local currentFusion = "Werewolf" -- Замените на текущее значение фушиона

-- Обработчик нажатия кнопки
script.Parent.MouseButton1Click:Connect(function()
	local currentFusionData, nextFusionData = getCurrentAndNextFusion(currentFusion)

	if currentFusionData then
		price2.Text = "Price: " .. currentFusionData.price .. " price"
		boostLabel.Text = "💪: x" .. currentFusionData.boost
		yourfusionname.Text = "Your Fusion: " .. currentFusionData.name -- Изменение на показ фушиона игрока

		if nextFusionData then
			nextBoostLabel.Text = "Next Boost: x" .. nextFusionData.boost
			nextFusionLabel.Text = "Next Fusion: " .. nextFusionData.name
			nextFusionLabel.Text = nextFusionData.name
		else
			nextBoostLabel.Text = "Next Boost: MAX"
			nextFusionTitleLabel.Text = "Next Fusion: MAX"
			nextFusionLabel.Text = "MAX"
		end

		-- Обновление текущего фушиона на следующий
		currentFusion = nextFusionData and nextFusionData.name or currentFusion

		-- Вызываем событие на сервере для покупки
		game:GetService("ReplicatedStorage").FusionUp:FireServer()
	end
end)

This is a script for buying a fushion

Please make your edits in the post, and don’t comment the edits. This is mentioned in the DevForum’s rules.

Edit: You should type your post fully completed before posting it. It’s a good habit to have.

3 Likes

I think the script is bugged or deprecated, maybe.

No errors, output is clean Doesn’t show

ЭThis is still relevant and I need help

Please keep your sentences in one post.

2 Likes

Is your script disabled?

Which one exactly? I didn’t understand what script you’re talking about.

He doesn’t listen. I gave him a great demonstration of how module scripts work yesterday and he was using profanity to demand people to help him and complaining that my place looks “weird and strange” when all it was is 2 scripts and the default baseplate to show how to use modules. Thankfully dev forum moderation has been on top of him. Just flag it when you see him breaking the rules.

2 Likes

You were offended because I couldn’t open your file and wrote strangely because strangely it didn’t open

I can work with modular scripts, I meant complex scripts like yesterday’s

This is still relevant, I haven’t found any errors and I don’t know what the problem is.

This is relevant, I still don’t know how to fix it