Classes don't work when I buy them help me fix it

  1. What do you want to achieve? Keep it simple and clear!fix the problem: when I write the path to leaderstats in the script where the class is bought, I can’t buy the multiplier, but when I write the path to the leaderstat multiplier, I can’t buy the classes

  2. What is the issue? Include screenshots / videos When I write the path to leaderstats in the script where the class is purchased, I can’t buy the multiplier, and when I write in the multiplier to leaderstats path, I don’t buy classes help fix

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?no one has been able to solve

local event = game.ReplicatedStorage.AddStat
local alertClients = game.ReplicatedStorage.ServerMessage
local MarketPlaceService = game:GetService("MarketplaceService")

local gamepassId = 257905319
local strengthPass = 257904902
local endPass = 257904475

local mults = require(game.ServerStorage.classMults)

local function ownsgamepass(userId, gamepassId)
	local ownsGamepass
	local s,res = pcall(function()
		ownsGamepass = MarketPlaceService:UserOwnsGamePassAsync(userId, gamepassId)
	end)

	return ownsGamepass
end
event.OnServerEvent:Connect(function(player, stat, val, op)
	local value = val -- to not alter original value
	local owns = ownsgamepass(player.UserId, gamepassId)
	if (stat == "Strength" and ownsgamepass(player.UserId, strengthPass))
		or (stat == "Endurance" and ownsgamepass(player.UserId, endPass)) then
		value *= 2
	end
	if stat.ClassName ~= "StringValue" and type(value)~='number' then
		warn("value is not number. the value is", value, "the stat is", stat)
	end
	if op == "+" then
		
		if player.Character.SafeZone.Start.Value == true then
			player:WaitForChild(stat).Value += value * value
		end
		
		if owns then
			player:WaitForChild(stat).Value += value * 2
		else
			player:WaitForChild(stat).Value += value
		end
	elseif op == "set" then
		if typeof(value)=="number" and owns and not stat:match("Multi") then
			--print(value)
			player.:WaitForChild(stat).Value = value * 2
		else
			player:WaitForChild(stat).Value = value
		end
		if val:match("Class") then
			alertClients:FireAllClients(player.Name.." has ranked up to "..value.."!") -- doesn't need player to send to
		end
	end
end)
2 Likes

This is where I write the path to leaderstats like this I won’t be able to buy a multiplier then

player.leaderstats:WaitForChild(stat).Value = value

Here I wrote the path to leaderstats but I can’t buy the classes

help me to fix i dont know How to fix the problem

Where have you defined event?

What event are you talking about

guys, it’s still relevant, help solve the problem

What he means is when you wrote it, you did this:

 event.OnServerEvent:Connect(function(player, stat, val, op) -- WHERE DID YOU ADD A variable FOR EVENT
	local value = val -- to not alter original value
	local owns = ownsgamepass(player.UserId, gamepassId)
	if (stat == "Strength" and ownsgamepass(player.UserId, strengthPass))
		or (stat == "Endurance" and ownsgamepass(player.UserId, endPass)) then
		value *= 2
	end

Where is the variable for event?

1 Like

I found it
local event = game.ReplicatedStorage.AddStat

help solve the problem please people

This is still relevant, yes, I would like to solve this problem as soon as possible

Hey, I will try to help you! let me know If you get any errors! :slight_smile:

local MarketPlaceService = game:GetService("MarketplaceService")
local event = --[[ your event here ]]

local gamepassId = 257905319
local strengthPass = 257904902
local endPass = 257904475

local function ownsgamepass(userId, gamepassId)
    local ownsGamepass = false
    local success, res = pcall(function()
        ownsGamepass = MarketPlaceService:UserOwnsGamePassAsync(userId, gamepassId)
    end)
    return success and ownsGamepass
end

event.OnServerEvent:Connect(function(player, stat, val, op)
    local value = val
    local owns = ownsgamepass(player.UserId, gamepassId)
    local playerStat = player.leaderstats:FindFirstChild(stat)

    if not playerStat then
        warn("Stat not found for player:", player.Name, "Stat:", stat)
        return
    end

    if (stat == "Strength" and ownsgamepass(player.UserId, strengthPass))
        or (stat == "Endurance" and ownsgamepass(player.UserId, endPass)) then
        value *= 2
    end

    if op == "+" then
        if player.Character and player.Character:FindFirstChild("SafeZone") and player.Character.SafeZone.Start.Value == true then
            playerStat.Value += value
        end
        if owns then
            playerStat.Value += value * 2
        else
            playerStat.Value += value
        end
    elseif op == "set" then
        if typeof(value) == "number" and owns and not string.match(stat, "Multi") then
            playerStat.Value = value * 2
        else
            playerStat.Value = value
        end
        if string.match(val, "Class") then
            -- Handle class purchase logic here
        end
    end
end)

I had an important thing here: when I bought a class in the chat, it was written, and you deleted it

guys help to fix so problem pls it so actualy problem

Make sure the logic for handling classes does not collide with the logic for handling multipliers and vice versa.

I’m new to writing scripts, can you explain again what the problem is approximately

Guys, help me fix this, is it still relevant, please help me

This is still a problem and I still can’t fix it.

Can you show me what is outputted in Output? Any errors?

I get the message “Infinite Search”

player:WaitForChild(stat).Value = value```