I don't know how to fix the script

You can get the current fusion like this:

local currentFusion = "Werewolf"
currentFusion,nextfusion = getCurrentAndNextFusion()

this replaces the current fusion with the owned.

2 Likes

I have a question if I do this I will be able to write what the next Fusion will be and I also have a problem after buying a Fusion dog I can’t write Lola like I don’t see the price

She disappears after buying a Fuschion dog

I left this is still relevant and I would like it to be the same when I I re-entered the game and I will have information about the boost price, what the next fushion will be and what fushion and boost I have

I can’t do this, please help me do it, I don’t know, I’ve already racked my brains

What you wrote doesn’t work. I tried

Help me fix this, it’s still relevant, I haven’t solved it yet

You need to use Data Stores for that. You also shouldn’t be handling purchases on the client; your game is vulnerable to exploiters

hmm why do I need a date store in the local script and I have a date store I have the same script only the purchase of the class is saved there but it doesn’t work in this I can’t do it

here I have this, only this is another script, but it works everything you need is here and I would like this script to be in the one in which the boost is saved, what will be the next fushion, what will be the price, what kind of fushion do you have, what kind of boost

local player = game.Players.LocalPlayer --// ADDED

local tp = player["TotalPower"]
local class = player.leaderstats.Class

local reset = game.ReplicatedStorage.ResetStats
local setClass = game.ReplicatedStorage.AddStat

local currentClass --// Value to use only for GUI not for anything else
local selectedClass
local accepted = {"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" }
local boosts = {["F-Class"]=2, ["E-Class"]=5, ["D-Class"]= 20, ["C-Class"]= 100, ["B-Class"]=500, ["A-Class"]=2500, ["S-Class"]=12500, ["SS-Class"]=150000, ["SSS-Class"]=1500000, ["X-Class"]=30000000, ["Y-Class"]=1000000000, ["Z-Class"]=40000000000, ["XYZ-Class"]=400000000000}
local tpNeeded = {["F-Class"]=1000000, ["E-Class"]=100000000, ["D-Class"]=20000000000, ["C-Class"]=3990000000000, ["B-Class"]=5000000000000000, ["A-Class"]=99000000000000000000,["S-Class"]=100000000000000000000000,["SS-Class"]=4990000000000000000000000000,["SSS-Class"]=10000000000000000000000000000000000,["X-Class"]= 50000000000000000000000000000000000000000,["Y-Class"]=100000000000000000000000000000000000000000000,["Z-Class"]=10000000000000000000000000000000000000000000000,["XYZ-Class"]=24800000000000000000000000000000000000000000000000   }

--local desc = script.Parent.Parent.Desc
--local NameText = script.Parent.Parent.NameText
local price = script.Parent.Parent.PriceText
--local boost = script.Parent.Parent.BoostText
local name = script.Parent.Parent.ClassNameText
local classname = script.Parent.Parent.ClassNameText --// Why are you repeating?


--// START OF ADDED STUFFS
local mainHolder = script.Parent.Parent
local boost = script.Parent.Parent.YourBoost

local nextclass = mainHolder.NextClassName2
local nextBoost = mainHolder.NextBoostText

local debounce = false --// For Spam Issues, incase if this is the cause to purchasing 2 classes
--// END OF ADDED STUFFS

---------------------------------------------------------------------

local function abbreviateNumber(number)
	if tonumber(number) == nil then warn("number expected got "..typeof(number)) ; return number end
	
	local abbreviations = 
	{
		{1e48, "QnD"}, {1e45, "QaD"}, {1e42, "Td"}, {1e39, "Dd"}, {1e36, "UnDc"}, {1e33, "Dc"}, {1e30, "No"}, {1e27, "Oc"},
		{1e24, "Sp"}, {1e21, "Sx"}, {1e18, "Qn"}, {1e15, "Qa"}, {1e12, "T"}, {1e9, "B"}, {1e6, "M"}, {1e3, "K"}
	}

	for _, abbreviation in ipairs(abbreviations) do
		local value, symbol = unpack(abbreviation)
		if math.abs(number) >= value then
			return string.format("%.1f%s", number / value, symbol)
		end
	end

	return tostring(number)
end


--------------------------------------------------------------------- ADDED new function (Change Text when player class changes)


local function ChangeText()
	
	local class_Num = table.find(accepted, tostring(class.Value)) or 0
	
	currentClass = accepted[class_Num] ~= nil and  accepted[class_Num]    or    "N/A" --// Class is considered for GUI as N/A if class_Num is less than 1 and more than 13
	selectedClass = ((accepted[class_Num+1] ~= nil) and accepted[class_Num + 1]    or   (class_Num+1 == #accepted+1) and "MAXED OUT"    or    "ERROR") --//  consider Class exist in table if the requirements are met or N/A if less than 1 or more than 14 and Reached last Stage if 14
	
	print(currentClass, selectedClass,  class_Num)
	classname.Text = currentClass
	boost.Text = (boosts[currentClass] == nil and "" or "Boost : "..abbreviateNumber(boosts[currentClass])) -- Используем функцию abbreviateNumber для сокращения числа

	nextclass.Text = selectedClass
	nextBoost.Text = (boosts[selectedClass] ~= nil and "Boost : "..abbreviateNumber(boosts[selectedClass]) or "")
	
	local needed = (table.find(accepted, selectedClass) == nil) and ""   or   (tpNeeded[selectedClass] ~= nil) and tpNeeded[selectedClass]   or   "ERROR"
	price.Text = (typeof(needed) == "number") and abbreviateNumber(needed) or needed
	
	if price.Text == "" or price.Text == nil then -- Make button invisible if price is not shown
		script.Parent.Visible = false
	else
		script.Parent.Visible = true
	end
	
end


---------------------------------------------------------------------


script.Parent.MouseButton1Click:Connect(function()
	if debounce == true then return end --// ADDED for extra Pre-caution (May not need this)
	debounce = true --// ADDED
	
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Workspace.SpawnLocation.CFrame
	
	local Class_Number = table.find(accepted, tostring(class.Value)) or 0

	selectedClass = 'F-Class'
	currentClass = "N/A"

	if Class_Number ~= nil then
		currentClass = accepted[Class_Number]
		selectedClass = accepted[Class_Number + 1]
	end
	
	--print(selectedClass)
	
	
	
	if selectedClass and class.Value ~= selectedClass then
		
		local needed = tpNeeded[selectedClass]
		price.Text = abbreviateNumber(needed) -- Используем функцию abbreviateNumber для сокращения числа
		
		if tp.Value >= needed then
			setClass:FireServer("Class", selectedClass, "set")
			reset:FireServer()
		end
	else
		print("LAST CLASS REACHED OR ERROR") --// Modified old comment to print statement
	end
	
	wait(.1)
	debounce = false
end)

ChangeText()
class.Changed:Connect(ChangeText)

You’re only saving their data in that server; you’re not saving their data across different sessions.

If you leave and join the same server, you keep your data; however, if you leave and join a different server, you lose all your data.


I recommend following a client → server Data Store tutorial since looking at your code, you’d need to change a lot of it in order to make it secure (you’re trusting the client on everything)

what’s with the inconsistencies…?

the code you’re provided in the post (which looks very ai generated to me but i won’t judge) has russian comments and some strange variables

strange variables:
image

yourboost?
yourfusionlabel?
nextboostlabel?
nextfusiontitlelabel?

and then suddenly in the script i’m replying to, your programming style is… a lot different

fishy, that’s all i’m saying

1 Like

I fixed it in English, I forgot what I wrote in Russian, and it’s still relevant. I want the script to know what the player’s fusion is and if the player has a fusion from the table, he can buy the next fusion.

I wrote these variables to make it easier to understand.

I think you need to use datastoreservice if you want to make sure the player keeps that specific fusion. I’m not really skilled at scripting all of that but there’s multiple tutorials and people out to help.

  1. Set up DataStoreService
    You’ll first need to save the player’s fusion when they purchase it, and then load it when they rejoin. This requires both saving the fusion after purchase and loading the fusion when the player joins the game.

  2. Modify Your Script
    I’ll walk you through both the client and server-side logic changes you’ll need.

Server-Side (Saving Fusion Data)
You need a server script that manages the DataStore:

local DataStoreService = game:GetService("DataStoreService")
local fusionStore = DataStoreService:GetDataStore("PlayerFusion")

-- Function to save player's fusion data
game:GetService("Players").PlayerRemoving:Connect(function(player)
    local currentFusion = player:FindFirstChild("CurrentFusion")
    if currentFusion then
        local success, err = pcall(function()
            fusionStore:SetAsync(player.UserId, currentFusion.Value)
        end)
        if not success then
            warn("Failed to save fusion for player: " .. err)
        end
    end
end)

-- Function to load player's fusion data
game:GetService("Players").PlayerAdded:Connect(function(player)
    local success, fusion
    local currentFusion = Instance.new("StringValue")
    currentFusion.Name = "CurrentFusion"
    currentFusion.Value = "Werewolf"  -- Default fusion
    currentFusion.Parent = player
    
    success, fusion = pcall(function()
        return fusionStore:GetAsync(player.UserId)
    end)
    
    if success and fusion then
        currentFusion.Value = fusion
    else
        warn("Failed to load fusion for player: " .. tostring(fusion))
    end
end)

Client-Side Changes
In your existing local script, you’ll need to:

  1. Access the player’s saved fusion when they join the game.
  2. Update currentFusion accordingly.

Modify the part where you set the initial value of currentFusion to check for the player’s stored fusion:

local function updateFusionFromServer()
    local currentFusionValue = LocalPlayer:FindFirstChild("CurrentFusion")
    if currentFusionValue then
        currentFusion = currentFusionValue.Value
        updateFusionDisplay()
    end
end

-- Call this function when the player joins
updateFusionFromServer()

In the part of the script where the player buys a fusion, you’ll also want to update the CurrentFusion value on the client:

-- When the player buys a fusion
currentFusion = nextFusionData and nextFusionData.name or currentFusion
LocalPlayer.CurrentFusion.Value = currentFusion  -- Update the player's current fusion

Summary of Changes

  1. Server-side script: Saves and loads the player’s fusion using DataStoreService.
  2. Client-side script: Retrieves and updates the fusion when the player joins and when they purchase a new fusion.

Didn’t test this and it is a datastore so I’m sure it will need some love.
Think you willl need a datastore for what you’re asking …

Scripting
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local fusionStore = DataStoreService:GetDataStore("PlayerFusions")

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

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}
}

local currentFusion = "Werewolf"

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

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

local function loadPlayerData(player)
    local success, data = pcall(function()
        return fusionStore:GetAsync(player.UserId)
    end)

    if success and data then
        currentFusion = data.currentFusion or currentFusion
        for i, fusion in ipairs(fusionData) do
            fusion.owned = data.ownedFusions and data.ownedFusions[fusion.name] or false
        end
    end

    updateFusionDisplay()
end

local function savePlayerData(player)
    local ownedFusions = {}
    for _, fusion in ipairs(fusionData) do
        ownedFusions[fusion.name] = fusion.owned
    end

    local data = {
        currentFusion = currentFusion,
        ownedFusions = ownedFusions
    }

    pcall(function()
        fusionStore:SetAsync(player.UserId, data)
    end)
end

Players.PlayerAdded:Connect(function(player)
    loadPlayerData(player)
end)

Players.PlayerRemoving:Connect(function(player)
    savePlayerData(player)
end)

script.Parent.MouseButton1Click:Connect(function()
    local currentFusionData, nextFusionData = getCurrentAndNextFusion()

    if currentFusionData then
        local totalPower = LocalPlayer:FindFirstChild("TotalPower")
        if totalPower and totalPower.Value >= currentFusionData.price then
            if not currentFusionData.owned then
                game:GetService("ReplicatedStorage").FusionUp:FireServer(currentFusion)
                currentFusionData.owned = true
                currentFusion = nextFusionData and nextFusionData.name or currentFusion
                totalPower.Value = totalPower.Value - currentFusionData.price
                updateFusionDisplay()
                savePlayerData(LocalPlayer)
            else
                print("You already own this fusion.")
            end
        else
            print("Not enough total power to purchase the fusion.")
        end
    end
end)

Thanks for helping, but I have a data store and this is a local script, and my fusion is saved, but the script does not see it. I can buy fusion by re-entering the game. I want the script to see it. What is the player’s fushion and sold the next fushion nursery the player has a fushion from the list of tables

Sorry for the last words, the translator translated poorly, I want the script to check what fusion the player has and sell the next fusion

Then add that to it in your datastore. I just put that together in a few minutes as more of an outline.
Only way I can think of to save anything past shutting down.