Hi,
I added to my tycoon battery that open door when it’s 0% and it can be charged by click (+10%) and upgrader for this battery (2x bigger battery life) but when i upgrade the battery nothing works…
script.Parent.ClickDetector.MouseClick:Connect(function()
if script.Parent.Value.Value >= 90 then
script.Parent.Value.Value = 100
script.Parent.BillboardGui.TextLabel.Text = script.Parent.Value.Value.."%"
else
script.Parent.Value.Value += 10
script.Parent.Transparency = 0
script.Parent.Material = "Neon"
script.Parent.BillboardGui.TextLabel.Text = script.Parent.Value.Value.."%"
workspace.WO.BaseDoorWO.CanTouch = true
workspace.WO.BaseDoorWO.Transparency = 0.8
end
end)
while wait(1) do
if workspace.WO.Owned.Value == true and script.Parent.Value.Value > 0 then
if script.Parent.Gamma.Value == true then
script.Parent.Value.Value -= 0.5
script.Parent.BillboardGui.TextLabel.Text = script.Parent.Value.Value.."%"
else
script.Parent.Value.Value -= 1
script.Parent.BillboardGui.TextLabel.Text = script.Parent.Value.Value.."%"
end
elseif script.Parent.Value.Value == 0 then
script.Parent.Transparency = 0.8
script.Parent.Material = "Glass"
workspace.WO.BaseDoorWO.CanTouch = false
workspace.WO.BaseDoorWO.Transparency = 1
end
end
I haven’t fully read your code, but do know that you can store values in variables right? This can make your code much easier to read and write. This would look like this:
local Parent = script.Parent -- the parent of the script
local Value = Parent.Value -- the number value
local Gamma = Parent.Gamma
local TextLabel = Parent.BillboardGui.TextLabel -- your text label
local WO = workspace.WO -- The base I think?
local DoorWO = WO.BaseDoorWO -- The base door
local Owned = WO.Owned -- the bool value
script.Parent.ClickDetector.MouseClick:Connect(function()
if Value.Value >= 90 then
Value.Value = 100
TextLabel.Text = Value.Value.."%"
else
Parent.Transparency = 0
Parent.Material = "Neon"
Value.Value += 10
TextLabel.Text = Value.Value.."%"
DoorWO.CanTouch = true
DoorWO.Transparency = 0.8
end
end)
while wait(1) do
if Owned.Value == true and Value.Value > 0 then
if Gamma.Value == true then
Value.Value -= 0.5
TextLabel.Text = Value.Value.."%"
else
Value.Value -= 1
TextLabel.Text = Value.Value.."%"
end
elseif Value.Value == 0 then
Parent.Transparency = 0.8
Parent.Material = "Glass"
DoorWO.CanTouch = false
DoorWO.Transparency = 1
end
end
Also, how is your system set up? Can you show a screenshot of the objects in the explorer? Also, how are you deciding how much power the battery can store? I don’t see anything in your code that limits it. Can you explain the variables?
It isn’t supposed to work. I didn’t change any of the functioning of the script. All I did was add variables so it’s easier to read. I remarked below the script that you need to provide more information about what values do what. Also, can you only paste the specific segment of code where you are trying to make the door store more power? I currently can’t tell where in your code you are attempting to do this because I don’t understand what each value/objects purpose is.
IntValue should only be used for whole numbers. Use NumberValue if you’d like to integrate any decimal values. I’d suggest that if you’re using a NumberValue, to also wrap it in math.floor.
what you said said here doesn’t make sense, as it’d defeat the whole point of the number values in the first place. The number values is meant to be able to store doubles, or floats, so using math.floor on it would make no sense and defeat the purpose of having it.
I was basing it off of what he said, which is all I know. He said something about percentages. So if he does have any decimals, he’ll need to multiply it and wrap it in a math.floor to get the percentage.
That isn’t how math.floor works. math.floor basically remove the decimal value of a number. Quoted directly from the math | Roblox Creator Documentation page it, “Returns the largest integer smaller than or equal to x.” You can think of it as rounding down to an integer. Here is what it’d do:
print(math.floor(3.9) == 3) -- true because math.floor(3.9) returns 3.
The inverse of math.floor, which is math.ceil basically rounds up to the nearest integer. This can be seen by this:
print(math.ceil(3.01) == 4) true because math.ceil(3.01) returns 4
Alright, well based on what he says, I assumed he would be displaying the battery percentage somewhere. If that’s the case, that’s what he’d use math.floor for. For example:
print(math.floor(.3248284823 / 1 * 100))
prints 32 which is 32%.
He is, but not in that way. I understand what you are trying to say though. He is instead taking the value directly and concatenating it with the % sign.