#Simple error : I want to not go into negatives
87 messages · Page 1 of 1 (latest)
returns the maximum of two given numbers
local SharedVariables = {}
SharedVariables.ReadyToShape = 0
return SharedVariables
Where do I put that?
In the module?
when you decrease it
** You are now Level 2! **
SO I put what you wrote in the part of the script where I decrease it after spawning in the shaping center?
Thanks btw u really are elping
in the script you use to decrease
To decrease the variable?
And lastly, do I put it before I decrease or after
SharedVariables.ReadyToShape = SharedVariables.ReadyToShape - 1
?
please man
after
Can you write it out so I understand?
function onAreaEnter()
SharedVariables.ReadyToShape =
math.max(0, SharedVariables.ReadyToShape -1)
What's function onAreaEnter()
this will either return 0 or shared variables -1
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
put it in whatever function you call when area entered
local function createEllipsoidShape()
...
SharedVariables.ReadyToShape = math.max(0, SharedVariables.ReadyToShape - 1)
end
Thank you so much
** You are now Level 5! **
I'll test it
IT WORKS!
Berghild, would you mind if I ask one final question @languid silo
its more simple
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
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
Thanks so much
So I get rid of the thing we did earlier
yeah the script won't run when its lesser than 1 anyways
These ... how much code are they?
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
just after the declaration of createEllipsoidShape
Ok @berghild, I'll edit the message above with the script tell me if im right
Done?
@languid silo
get rid of the last part
Which part
SharedVariables.ReadyToShape = math.max(0, SharedVariables.ReadyToShape - 1)
end
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
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
** You are now Level 3! **
Because I want to it to take off one on the variable so that it shows the wait list is shorter
that means isn't equal to
x -= 1 means x = x -1
Thanks man