Hello everyone I created a script for buying a fushion and when I buy the next fushion and exit, I go in and click buy, the previous fushions are bought from me, or rather the initial fushions, and I don’t understand What’s the matter? The local script is responsible for purchasing the fusion, and the server script is responsible for providing the fusion.
local script
local player = game.Players.LocalPlayer
local totalPower = player:WaitForChild("TotalPower")
local fusion = player.leaderstats:WaitForChild("Fusion")
local buyFusion = game.ReplicatedStorage:WaitForChild("FusionUp") -- Event for buying fusions
local AbbreviateModule = require(game.ReplicatedStorage:WaitForChild("Abbreviate")) -- Load abbreviation module
local acceptedFusions = {
"None", "Werewolf", "Minotaur", "Gryphon",
"Phoenix", "Yeti", "Hydra", "Reaper"
}
local fusionBoosts = {
None = 0,
Werewolf = 25,
Minotaur = 500,
Gryphon = 10000,
Phoenix = 250000,
Yeti = 100000000,
Hydra = 100000000,
Reaper = 2000000000
}
local fusionPrices = {
None = 500,
Werewolf = 5e21,
Minotaur = 1.99e27,
Gryphon = 3e32,
Phoenix = 7e36,
Yeti = 5e41,
Hydra = 2e49,
Reaper = 15e51
}
-- Define required classes for each fusion card
local requiredClasses = {
None = nil,
Werewolf = "S-Class",
Minotaur = "SS-Class",
Gryphon = "SSS-Class",
Phoenix = "X-Class",
Yeti = "Y-Class",
Hydra = "Z-Class",
Reaper = "XYZ-Class"
}
-- Class hierarchy definition
local classHierarchy = {
"None", "F-Class", "E-Class", "D-Class", "C-Class", "B-Class",
"A-Class", "S-Class", "SS-Class", "SSS-Class", "X-Class",
"Y-Class", "Z-Class", "XYZ-Class"
}
-- Function to compare classes
local function hasRequiredClass(playerClass, requiredClass)
local playerClassIndex = table.find(classHierarchy, playerClass)
local requiredClassIndex = table.find(classHierarchy, requiredClass)
return playerClassIndex and requiredClassIndex and playerClassIndex >= requiredClassIndex
end
-- UI elements
local priceText = script.Parent.Parent.PriceText
local fusionNameText = script.Parent.Parent.ClassNameText
local yourBoostText = script.Parent.Parent.YourBoost
local nextFusionText = script.Parent.Parent.NextClassName2
local nextBoostText = script.Parent.Parent.NextBoostText
local classText = script.Parent.Parent.Cost_Title -- Assuming this is the class title text field
local imageFusion = script.Parent.Parent.ImageFusion
-- Dictionary of fusion images
local fusionImages = {
None = "rbxassetid://12345678", -- Replace with real image IDs
Werewolf = "rbxassetid://101327226569472",
Minotaur = "rbxassetid://87286241154287",
Gryphon = "rbxassetid://135121206180771",
Phoenix = "rbxassetid://116869246657778",
Yeti = "rbxassetid://75671867972101",
Hydra = "rbxassetid://86234585407677",
Reaper = "rbxassetid://78596750479540"
}
-- Debounce to prevent spamming
local debounce = false
-- Function to update the fusion display
local function updateFusionDisplay()
local currentIndex = table.find(acceptedFusions, fusion.Value) or 0
local selectedFusion = acceptedFusions[currentIndex + 1] or "MAX"
fusionNameText.Text = fusion.Value
yourBoostText.Text = "Boost: " .. AbbreviateModule.abbreviate(fusionBoosts[fusion.Value] or 0) -- Abbreviate Boost
nextFusionText.Text = selectedFusion
local nextPrice = fusionPrices[selectedFusion]
if nextPrice then
priceText.Text = "Price: " .. AbbreviateModule.abbreviate(nextPrice) .. " 💪" -- Abbreviate price
script.Parent.Visible = true
else
priceText.Text = "MAX"
script.Parent.Visible = false
end
nextBoostText.Text = "Next Boost: " .. AbbreviateModule.abbreviate(fusionBoosts[selectedFusion] or "MAX") -- Abbreviate Boost
-- Update the required class text for the next fusion
local requiredClass = requiredClasses[selectedFusion]
classText.Text = requiredClass and " " .. requiredClass or "No Class Required"
-- Update the current fusion image
if fusion.Value == "None" then
imageFusion.Visible = false -- Hide image if fusion is "None"
else
imageFusion.Image = fusionImages[fusion.Value] -- Set image for current fusion
imageFusion.Visible = true -- Show image
end
end
-- Function to handle fusion purchase
script.Parent.MouseButton1Click:Connect(function()
if debounce then return end
debounce = true
local currentIndex = table.find(acceptedFusions, fusion.Value) or 0
local selectedFusion = acceptedFusions[currentIndex + 1]
local requiredPrice = fusionPrices[selectedFusion]
local requiredClass = requiredClasses[selectedFusion]
-- Check if enough Total Power and if the required class is met
if totalPower.Value >= requiredPrice then
-- Check if player has the required class or is above it
if requiredClass == nil or hasRequiredClass(player.leaderstats.Class.Value, requiredClass) then
buyFusion:FireServer(selectedFusion) -- Send event to server for purchase
totalPower.Value -= requiredPrice -- Decrease Total Power
fusion.Value = selectedFusion -- Update current fusion
updateFusionDisplay() -- Update UI
-- Move player to spawn
local spawnLocation = workspace:FindFirstChild("SpawnLocation") -- Ensure you have a SpawnLocation object
if spawnLocation then
player.Character:MoveTo(spawnLocation.Position) -- Move player
else
warn("SpawnLocation not found.")
end
else
print("Required class for purchase: " .. requiredClass)
end
else
print("Not enough total power to buy fusion.")
end
wait(0.1) -- Pause before removing debounce
debounce = false
end)
-- Initialize display on startup
updateFusionDisplay()
-- Subscribe to fusion changes
fusion.Changed:Connect(updateFusionDisplay)