#Simple error : I want to not go into negatives

87 messages · Page 1 of 1 (latest)

languid silo
#

math.max(0,myVar)

dusty fog
#

ooh someones typing

#

I don't understand that sorry.

#

I'm a basic level scripter

dusty fog
#

Btw the variable is in a module script

languid silo
#

returns the maximum of two given numbers

dusty fog
#

local SharedVariables = {}

SharedVariables.ReadyToShape = 0

return SharedVariables

#

Where do I put that?

#

In the module?

languid silo
#

when you decrease it

agile stratusBOT
#

studio** You are now Level 2! **studio

dusty fog
#

Thanks btw u really are elping

languid silo
#

in the script you use to decrease

dusty fog
#

To decrease the variable?

dusty fog
#

SharedVariables.ReadyToShape = SharedVariables.ReadyToShape - 1

#

?

#

please man

languid silo
#

after

dusty fog
#

Can you write it out so I understand?

languid silo
#

function onAreaEnter()
SharedVariables.ReadyToShape =
math.max(0, SharedVariables.ReadyToShape -1)

languid silo
#

this will either return 0 or shared variables -1

dusty fog
#

I'll send you my original script.

#

local lastClickTime = 0
local cooldown = 2
local SharedVariables = require(game.ReplicatedStorage:WaitForChild("SharedVariables"))

local function createEllipsoidShape()
local part = Instance.new("Part")
part.Size = Vector3.new(3.403, 1.6, 3.962)
part.BrickColor = BrickColor.new("Wheat")
part.Material = Enum.Material.SmoothPlastic
part.Anchored = false
part.Position = Vector3.new(-39.24, 3.441, 19.116)
part:SetAttribute("Cookable", true)

local mesh = Instance.new("SpecialMesh", part)
mesh.MeshType = Enum.MeshType.Sphere
mesh.Scale = Vector3.new(0.5, 0.8, 0.5)

part.Parent = game.Workspace
SharedVariables.ReadyToShape = math.max(0, SharedVariables.ReadyToShape - 1)

end

local function onClick()
local currentTime = tick()

if currentTime - lastClickTime >= cooldown then
    createEllipsoidShape()
    lastClickTime = currentTime
else
    local remainingTime = cooldown - (currentTime - lastClickTime)
    print("Please wait " .. math.ceil(remainingTime) .. " more seconds before clicking again.")
end

end

local clickDetector = script.Parent:FindFirstChildOfClass("ClickDetector")
if clickDetector then
clickDetector.MouseClick:Connect(onClick)
else
print("Attach this script to a part with a ClickDetector")
end

languid silo
dusty fog
#

So here where do I put it?

#

The Ellipsoid shape is the dough @languid silo

languid silo
#

local function createEllipsoidShape()
...
SharedVariables.ReadyToShape = math.max(0, SharedVariables.ReadyToShape - 1)
end

dusty fog
#

Thank you so much

agile stratusBOT
#

studio** You are now Level 5! **studio

dusty fog
#

I'll test it

#

IT WORKS!

#

Berghild, would you mind if I ask one final question @languid silo

#

its more simple

languid silo
#

yeah

#

I mean no

#

I wouldn't mind

dusty fog
#

Alright.

#

So I think you kind of understand what my game is trying to do right now.

#

Looking at the script before I posted.

#

You can see that my script is, I press the button and it spawns a dough and then subtracts it.

#

But even if I go to 0 dough as thats the limit I want to make it so that you can only spawn a dough in the shaping center if you have 1+ dough.

#

Would I use a conditional at the beginning which is like if ReadyToShape >0

#

@languid silo

languid silo
#

local function createEllipsoidShape()
...
if SharedVariables.ReadyToShape < 1 then return end --script below won't run if condition is not met
--dougj spawning code here
SharedVariables.ReadyToShape -= 1

#

no need for max function in this case

dusty fog
#

Thanks so much

dusty fog
languid silo
#

yeah the script won't run when its lesser than 1 anyways

dusty fog
#

thanks man

#

ill test it now

#

@languid silo one question before I implement

dusty fog
#

So where in thsi script do I put that: local lastClickTime = 0
local cooldown = 2
local SharedVariables = require(game.ReplicatedStorage:WaitForChild("SharedVariables"))

local function createEllipsoidShape()
if SharedVariables.ReadyToShape < 1 then return end --script below won't run if condition is not met
--dougj spawning code here
SharedVariables.ReadyToShape -= 1
local part = Instance.new("Part")
part.Size = Vector3.new(3.403, 1.6, 3.962)
part.BrickColor = BrickColor.new("Wheat")
part.Material = Enum.Material.SmoothPlastic
part.Anchored = false
part.Position = Vector3.new(-39.24, 3.441, 19.116)
part:SetAttribute("Cookable", true)

local mesh = Instance.new("SpecialMesh", part)
mesh.MeshType = Enum.MeshType.Sphere
mesh.Scale = Vector3.new(0.5, 0.8, 0.5)

part.Parent = game.Workspace
SharedVariables.ReadyToShape = math.max(0, SharedVariables.ReadyToShape - 1)

end

local function onClick()
local currentTime = tick()

if currentTime - lastClickTime >= cooldown then
    createEllipsoidShape()
    lastClickTime = currentTime
else
    local remainingTime = cooldown - (currentTime - lastClickTime)
    print("Please wait " .. math.ceil(remainingTime) .. " more seconds before clicking again.")
end

end

local clickDetector = script.Parent:FindFirstChildOfClass("ClickDetector")
if clickDetector then
clickDetector.MouseClick:Connect(onClick)
else
print("Attach this script to a part with a ClickDetector")
end

languid silo
#

just after the declaration of createEllipsoidShape

dusty fog
#

Ok @berghild, I'll edit the message above with the script tell me if im right

#

Done?

#

@languid silo

languid silo
#

get rid of the last part

dusty fog
#

Which part

languid silo
#

SharedVariables.ReadyToShape = math.max(0, SharedVariables.ReadyToShape - 1)
end

dusty fog
#

Get rid of it completely or just math.max

#

Bc I still want it to remove by 1 so it shows that the dough has been gotten rid of the wait list and is now being shaped

#

Can you edit the script

#

@languid silo

languid silo
#

local function createEllipsoidShape()
if SharedVariables.ReadyToShape <1 then return end
SharedVariables.ReadyToShape -=1
local part = Instance.new("Part")
part.Size = Vector3.new(3.403, 1.6, 3.962)
part.BrickColor = BrickColor.new("Wheat")
part.Material = Enum.Material.SmoothPlastic
part.Anchored = false
part.Position = Vector3.new(-39.24, 3.441, 19.116)
part:SetAttribute("Cookable", true)

local mesh = Instance.new("SpecialMesh", part)
mesh.MeshType = Enum.MeshType.Sphere
mesh.Scale = Vector3.new(0.5, 0.8, 0.5)

part.Parent = game.Workspace
agile stratusBOT
#

studio** You are now Level 3! **studio

dusty fog
#

Thank you so much but one thing

#

Why did you get rid of the readytoshape - 1

languid silo
#

you don't need that

#

-= 1 does the same

dusty fog
#

Because I want to it to take off one on the variable so that it shows the wait list is shorter

dusty fog
languid silo
#

x -= 1 means x = x -1

dusty fog
#

oh

#

thanks so much

languid silo
#

you're welcome

dusty fog
#

Thanks man

languid silo
#

same with any operator

#

+= *=

#

saves you time

dusty fog
#

thanks

#

It works fantastically man you are the goat