there is no my player chooses a class and there is no notification
Okay, when the player chooses the class, they rank up to the class automatically, but to get the class they get a boost, but is that part implemented already yet or is there work for it?
Yes there is, I did this: the player chooses a class, then presses the buy button
Okay, it’s good. When the player presses buy, is the class bought yet, then the player sees the next class to buy?
no but I want to add this I have only 2 classes in the game
That’s good. When the player upgrades the class, is there a specific struggle that is having problems, or is it not implemented yet? It’s not very easy to tell from the current script.
when I buy a class, all the power disappears, but I don’t get a boost
I see. In the script, it doesn’t look like the multiplier is applied. Maybe it should have an or
with the condition to check if the player is the class on the server script using the module “classMults”.
classMults.fClass = 1
classMults.dClass = 2
return classMults
Yes, but where the module is used. In the server script, try this.
local event = game.ReplicatedStorage.AddStat
local alertClients = game.ReplicatedStorage.ServerMessage
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassId = 251841658
local strengthPass = 251310188
local endPass = 251310008
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 op == "+" then
if owns then
player:WaitForChild(stat).Value += value * 2
else
player:WaitForChild(stat).Value += value
end
elseif op == "set" then
if owns and not stat:match("Multi") then
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)
You need to add the code to multiply the new values with the class using the classMults module on the server, but on the one time use category classes I’m not sure if it’s intended to do that or just multiply it once or for new stats.
ok I inserted this into my script thank you
I meant the multiplication module:
You should put that on the client, because I don’t think the gamepass and the class are in relation.
ServerScriptService.AddStatScript:35: attempt to perform arithmetic (mul) on string and number - Server - AddStatScript:35
Try this:
local event = game.ReplicatedStorage.AddStat
local alertClients = game.ReplicatedStorage.ServerMessage
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassId = 251841658
local strengthPass = 251310188
local endPass = 251310008
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 op == "+" then
if owns then
player:WaitForChild(stat).Value += value * 2
else
player:WaitForChild(stat).Value += value
end
elseif op == "set" then
if 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)
tell the white log message before the error in this code, just to see what the value data actually is.
ServerScriptService.AddStatScript:36: attempt to perform arithmetic (mul) on string and number - Server - AddStatScript:36
local event = game.ReplicatedStorage.AddStat
local alertClients = game.ReplicatedStorage.ServerMessage
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassId = 251841658
local strengthPass = 251310188
local endPass = 251310008
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
error("value is not number. the value is", value, "the stat is", stat)
end
if op == "+" then
if owns then
player:WaitForChild(stat).Value += value * 2
else
player:WaitForChild(stat).Value += value
end
elseif op == "set" then
if 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)
This one should have a more detailed error message
ServerScriptService.AddStatScript:28: invalid argument #2 to ‘error’ (number expected, got string) - Server - AddStatScript:28
I’m sorry to distract you, you have corrected there is simply no answer from you
get class Mults script
func.OnServerInvoke = function(player)
local class = player.Class
local mults = require(game.ServerStorage["classMults"])
local classMult
if class.Value == "F-Class" then
classMult = mults.fClass
elseif class.Value == "D-Class" then
classMult = mults.dClass
end
return classMult
end
Sorry, I was offline for some time since it was late when I was writing that. I won’t be online for a while.
That’s a weird error. Try changing error
to warn
.