Hello everyone, I created a script and I don’t know how to make it so that when you re-enter the game, the script checks what kind of fusion you have so that you don’t have to buy the same fusion forever. How can I make it so that
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
-- Tables with data on fusions and boosts
local fusionData = {
{name = "Werewolf", price = 500, boost = 2, owned = false},
{name = "Minotaur", price = 1000, boost = 4, owned = false},
{name = "Dog", price = 5000, boost = 8, owned = false},
{name = "Lola", price = 10000, boost = 16, owned = false}
}
-- Initial value for the current fusion
local currentFusion = "Werewolf"
-- Function to get the current and next fusion
local function getCurrentAndNextFusion()
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
-- Update the displayed information about fusions
local function updateFusionDisplay()
local currentFusionData, nextFusionData = getCurrentAndNextFusion()
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
else
nextBoostLabel.Text = "Next Boost: MAX"
nextFusionTitleLabel.Text = "Next Fusion: MAX"
nextFusionLabel.Text = "MAX"
price2.Text = ""
end
end
end
-- Initialize the display
updateFusionDisplay()
-- Button click handler
script.Parent.MouseButton1Click:Connect(function()
local currentFusionData, nextFusionData = getCurrentAndNextFusion()
if currentFusionData then
-- Check total power
local totalPower = LocalPlayer:FindFirstChild("TotalPower")
if totalPower and totalPower.Value >= currentFusionData.price then
-- Check if the fusion has already been purchased
if not currentFusionData.owned then
-- Fire an event on the server to purchase
game:GetService("ReplicatedStorage").FusionUp:FireServer(currentFusion)
-- Mark the current fusion as owned
currentFusionData.owned = true
-- Update the current fusion to the next one
currentFusion = nextFusionData and nextFusionData.name or currentFusion
-- Decrease the player's Total Power
totalPower.Value = totalPower.Value - currentFusionData.price
-- Update the display
updateFusionDisplay()
else
print("You already own this fusion.")
end
else
print("Not enough total power to purchase the fusion.")
end
end
end)