My script does not work after the player re-enters

Try and debug this, print those 2 vars after getting them. Try and buy 2 times, tell me what it prints

2 - Client - LocalScript:89
17:44:32.507 Minotaur - Client - LocalScript:90

And look what I noticed here is minotaur and in the server script it displays werewolf

It turns out we are on the right track

use this as a for your server script:

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local event = RS.ServerMessage  -- Make sure this event exists in ReplicatedStorage
local ranks = require(game:GetService("ServerStorage").FusionsModule)

RS.FusionUp.OnServerEvent:Connect(function(player, power)
	local tp = player:FindFirstChild("TotalPower") -- Make sure TotalPower exists
	if not tp then
		print("TotalPower not found.")
		return
	end

	-- Collect all owned ranks
	local ownedRanks = {}
	for _, rank in pairs(ranks) do
		if rank["Owned"] then
			table.insert(ownedRanks, rank)
		end
	end

	-- Check if there are owned fusions
	if #ownedRanks == 0 then
		print("You do not own any fusions.")
		return
	end

	-- Get the best fusion
	local nextRank = power
        print(nextRank)

	if nextRank then
                 print("Next Rank Found")
		if tp.Value >= nextRank.Price then
                        print("Executing")
			-- Reset player values
			player.Strength.Value = 0
			player.Psp.Value = 0
			player.Endurance.Value = 0
			player.Agility.Value = 0

			-- Set the class
			if player.leaderstats then
				player.leaderstats.Class.Value = "F-Class"
			end

			-- Update the best fusion
			player.leaderstats.Fusion.Value = nextRank.Name
			player.BestFusion.FusionMulti.Value = nextRank.Multi

			-- Mark the next fusion as owned
			nextRank.Owned = true

			-- Reset ownership of previous fusions
			for i, rank in pairs(ranks) do
				if rank.rank <= bestRank.rank then
					rank.Owned = false
				end
			end

			-- Deduct Total Power from the player by the fusion's price
			tp.Value = tp.Value - nextRank.Price

			-- Send a message about the fusion purchase
			event:FireAllClients(player.Name .. " Buy Fusion: " .. nextRank.Name)

			print("You successfully purchased the fusion: " .. nextRank.Name)
		else
			print("Not enough Total Power to buy the next fusion.")
		end
	else
		print("You have reached the maximum fusion level.")
	end
end

Let me know if resolved/any issues happens or if there’s any prints done!

It didn’t help, I still bought a fusion after re-entering the game and was given a starting fusion

saving error then, you should revise your datastore/profileservice script

Should I send you my data store?

Would probably be too long, pretty sure you can ask ChatGPT about it and it’d give you updated scripts along with better explanations than mine!

To be honest, he wrote the entire script

ask him in a new chat for a new updated script w/ your datastore (make sure to detail everything)

I fixed it thanks to those who wanted to help and who helped fix it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.