Hello guys, I’m currently developing a Simulator and I need help with this.
When the player sells his Muscles, they get converted in Coins, but the Muscles should have a limit given by the Storage the player owns. So the issue is: If I have a weight that gives me 16 muscles for each lift, and my Storage Limit is 30, after 2 times that I lift the weight, instead of having 32 muscles, that 32 should become 30. This actually happens, but the issue is that yes, the value of the muscles becomes the exact value of the Storage, but the excess muscles remain stored somewhere and still get sold like if you had more points, past the limit of the Storage.
So, instead of selling for 30 Coins, I sell 30 Muscles but I get 32.
I was thinking about creating a RemoteEvent that could tell the server that the player was going past the given limit, but I don’t think it is a good idea, and if it is, any clue on how to organise that?
Thank you!
local value = math.clamp(value, minimumValue, maximumValue)
The value is unable to be lower than the minimumValue and unable to be greater than the maximumValue.
Here’s the API Document if you’re still unsure: math | Documentation - Roblox Creator Hub.
Just another question, I just got error, the math.clamp requires a Number so I can’t put “muscle” since it is an Instance, any idea on how to trick this?
This is the Sell script
local deb = false
local part = script.Parent
part.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if player then
if deb == false then
deb = true
script.Parent.Sell:Play()
local leaderstats = player:WaitForChild("leaderstats")
local OtherStats = player:WaitForChild("OtherStats")
local money = OtherStats.Coins
local Storage = OtherStats:WaitForChild("Storage").Value -- Default is 30
local Muscles = leaderstats:FindFirstChild("Muscle")
local Stage = leaderstats:FindFirstChild("Stage")
Muscles.Value = math.clamp(Muscles, 0, 30) -- At first I tried (Muscles, 0, Storage) but the same error occured
if Muscles.Value >= 0 then
money.Value = Muscles.Value + money.Value
Muscles.Value = 0
end
wait(2)
deb = false
script.Parent.Sell:Stop()
end
end
end
end)