local owns = ownsgamepass(player.UserId, gamepassId)
if stat == "Strength" and ownsgamepass(player.UserId, strengthPass)
or stat == "Endurance" and ownsgamepass(player.UserId, endPass) then
val = val*2
end
if op == "+" then
if owns then
player:WaitForChild(stat).Value += val*2
else
player:WaitForChild(stat).Value += val
end
elseif op == "set" then
if owns and not stat:match("Multi") then
player:WaitForChild(stat).Value = val*2
else
player:WaitForChild(stat).Value = val
end
There is a lot of flaws in your code, especially using MarketplaceService incorrectly
I rewrote it for you (it’s not tested yet)
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 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)
ServerScriptService.AddStatScript:33: attempt to perform arithmetic (mul) on string and number - Server - AddStatScript:33
What? You are sending a string to the server and multiplying it (oops wrong reply)
thank you for helping, but I would like that when a player clicks on a button, a class is bought from him without his choice, can you help me do it?
Can you explain more clearly about what you want to do?
look you see in the table in the right corner black is almost the color the player clicks on it he buys a class
will you help or test or what are you doing ?
I have never done this before so you might need to ask others
guys, someone help me do this, I need to do it before tomorrow, since the game is coming out tomorrow, I still need to have time to supplement the classes yet
guys please help this is a very necessary thing be kind
guys, I will be very grateful, help me do it, please, I don’t want to wait a long time, I need to do it today
It doesn’t look like you have a function for that one yet, since it should subtract from the Player stat
, but it isn’t included as a function on the server in the code. I might be confused.
But everything else looks like it should work, if not then check for an error.
Sorry, I’m weak in the script, what is stat?
You will help you write, we will analyze it together to understand what the problem is
The stat
meant stat in the script, if the translator did not translate the code snippet.
I just want the player not to choose which class to buy, but just start using the button, he bought the class automatically
and after the purchase, he wrote how much strength he needed and how much boost he would have and how much boost he had, that is, in the left corner he wrote the name of the class and the boost, and on the right how much boost there would be and how much total power he needed to gain to buy a class
So, the purchase is automatic. Is there a dialog box for notification of the purchase confirmation?