How do I make a button timer in Roblox? - roblox

I was creating an obby in Roblox, and I wanted to make a button that a player could step on to make the platforms in front of them solid. I checked the documentation, and I found nothing that seemed to help. Here is my code: (Ignore e, ee, eee, bt, bt1, bt2, and tch. They are my parts/variables/function names)
bt = game.Workspace.e.SurfaceGui.ButtonTimer
bt1 = game.Workspace.ee.SurfaceGui.ButtonTimer1
bt2 = game.Workspace.eee.SurfaceGui.ButtonTimer2
bt.Text = "hi "
bt1.Text = "hi "
bt2.Text = "hi "
script.Parent.Touched:Connect(function(tch)
if tch.Parent:FindFirstChild("Humanoid") then
game.Workspace.e.Transparency = 0
game.Workspace.e.CanCollide = true
game.Workspace.ee.Transparency = 0
game.Workspace.ee.CanCollide = true
game.Workspace.eee.Transparency = 0
game.Workspace.eee.CanCollide = true
bt.Text = "10"
bt1.Text = "10"
bt2.Text = "10"
wait(1)
bt.Text = "9"
bt1.Text = "9"
bt2.Text = "9"
wait(1)
bt.Text = "8"
bt1.Text = "8"
bt2.Text = "8"
wait(1)
bt.Text = "7"
bt1.Text = "7"
bt2.Text = "7"
wait(1)
bt.Text = "6"
bt1.Text = "6"
bt2.Text = "6"
wait(1)
bt.Text = "5"
bt1.Text = "5"
bt2.Text = "5"
wait(1)
bt.Text = "4"
bt1.Text = "4"
bt2.Text = "4"
wait(1)
bt.Text = "3"
bt1.Text = "3"
bt2.Text = "3"
wait(1)
bt.Text = "2"
bt1.Text = "2"
bt2.Text = "2"
wait(1)
bt.Text = "1"
bt1.Text = "1"
bt2.Text = "1"
wait(1)
bt.Text = "0"
bt1.Text = "0"
bt2.Text = "0"
game.Workspace.e.Transparency = 0.75
game.Workspace.e.CanCollide = false
game.Workspace.ee.Transparency = 0.75
game.Workspace.ee.CanCollide = false
game.Workspace.eee.Transparency = 0.75
game.Workspace.eee.CanCollide = false
else
game.Workspace.e.BrickColor = BrickColor.Red()
end
end)

i have created a timer in my game, I will share the code with you:
local timer = script.Parent
local minutes = 1
local seconds = 9
local adm = script.Parent.Parent
repeat
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
if seconds <= 9 then
timer.Text = "Vote time: "..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = "Vote time: "..tostring(minutes)..":"..tostring(seconds)
end
wait(1)
until minutes <= 0 and seconds <= 0

Related

Pine Script V5 - Not getting expected breakout entry price and entry in expected bar

I have a long entry buy condition where
Candle time frame is 15 minutes
Alert candle high is below lower band of bollinger bands.
entry when next candle crossover the alert candle high
This script gives entry oh high breakout + 0.01 but it does not give entry in the exact breakout candle and gives entry when price comes next time on expected entry price i.e. alert candle high + 0.01.
Requesting solution to get entry in breakout candle itself and at expected breakout price.
//#version=5
strategy("Bands Reversion", overlay=true, calc_on_every_tick=true)
//// Indicator Bollinger Bands
source = close
length = input.int(20, minval=1)
mult = input.float(1.5, minval=0.001, maxval=50)
direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)
strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
upper = basis + dev
lower = basis - dev
plot(basis, color = color.red)
plot(upper)
plot(lower)
/// Trade entry time and squareoff time
TradeTime = input(title="Trade Timings",defval="0930-1130")
SqoffTime = input(title="Squareoff Timings",defval="1530-1545")
Barsinsession(TradeTime) => time(timeframe.period,TradeTime) != 0
Insession = Barsinsession(TradeTime) ? 1 : 0
endofsession = Insession == 0 and Insession[1] == 1
Sqsession = Barsinsession(SqoffTime) ? 1 : 0
SqTime = Sqsession == 1 and Sqsession[1] == 0
//// Input control and conditions
buy_condition = high[1] < lower[1] and ta.crossover(high, high[1]) and Insession
short_condition = low[1] > upper[1] and ta.crossunder(low, low[1]) and Insession
buy_alert_high = ta.valuewhen(buy_condition, high[1],0)
buy_alert_low = ta.valuewhen(buy_condition, low[1],0)
short_alert_low = ta.valuewhen(short_condition, low[1],0)
short_alert_high = ta.valuewhen(short_condition, high[1],0)
buy_alert_high1 = ta.valuewhen(buy_condition, high,0)
plot(buy_alert_high, style = plot.style_circles)
plot(buy_alert_low, style = plot.style_circles, offset = -2)
plot(short_alert_low, style = plot.style_circles)
plot(short_alert_high, style = plot.style_circles)
sell = ta.crossunder(close, low) or SqTime //// or SqTime if for intraday exit
cover = ta.crossover(close,high) or SqTime //// or SqTime if for intraday exit
plotshape(buy_condition, style = shape.triangleup, location = location.belowbar, color = color.green, text = "BUY")
plotshape(short_condition, style = shape.triangledown, location = location.abovebar, color = color.red, text = "SHORT")
long_price = ta.valuewhen(buy_condition, (buy_alert_high + 0.01),0 )
longstop = buy_alert_low - 0.01
longtgt = basis
short_price = ta.valuewhen(short_condition,short_alert_low - 0.01,0) ////short_alert_low - (0.01 * 100 * syminfo.mintick) //// ta.valuewhen(short_condition,short_alert_low - 0.01,0)
shortstop = short_alert_high + 0.01
shorttgt = basis
strategy.entry("long",direction = strategy.long, when = buy_condition, limit = long_price, comment ="BUY")
strategy.close("long", when = sell, comment = "SELL")
strategy.exit("long", from_entry = "long", stop = longstop, limit = longtgt, comment = "TG/SL_EXIT")
strategy.entry("short",direction = strategy.short, when = short_condition,limit = short_price, comment ="SHORT")
strategy.close("short", when = cover, comment = "COVER")
strategy.exit("short", from_entry = "short", stop = shortstop, limit = shorttgt, comment = "TG/SL_EXIT")
plot(strategy.position_size > 0 ? longstop : na, style = plot.style_linebr, color = color.red)
plot(strategy.position_size > 0 ? longtgt : na, style = plot.style_linebr, color = color.green)
plot(strategy.position_size < 0 ? shortstop : na, style = plot.style_linebr, color = color.red)
plot(strategy.position_size < 0 ? shorttgt : na, style = plot.style_linebr, color = color.green)

Plotting a series of numbers into horizontal lines

I've been trying to figure out the code to plot lines like these based on me copy and pasting a series of numbers into the code each day. I was trying to use an array but I'm not sure that's what I need to do. Any help would be greatly appreciated!
Example
//#version=5
indicator("Input Levels", overlay = true)
lev1 = input.float(3990, title = "Val 1", inline = "1")
col1 = input.color(color.black, title = "", inline = "1")
lev2 = input.float(3890, title = "Val 2", inline = "2")
col2 = input.color(color.green, title = "", inline = "2")
lev3 = input.float(3995, title = "Val 3", inline = "3")
col3 = input.color(color.black, title = "", inline = "3")
lev4 = input.float(3870, title = "Val 4", inline = "4")
col4 = input.color(color.red, title = "", inline = "4")
lev5 = input.float(3826, title = "Val 5", inline = "5")
col5 = input.color(color.black, title = "", inline = "5")
var float[] level_vals = array.from(lev1, lev2, lev3, lev4, lev5)
var color[] color_vals = array.from(col1, col2, col3, col4, col5)
var line[] level_lines = array.new_line()
size = array.size(level_vals)
if barstate.isfirst
for i = 0 to size - 1
array.push(level_lines, line.new(x1 = na, y1 = na, x2 = na, y2 = na, style = line.style_dashed, color = color.black, extend = extend.both))
if barstate.islast
for i = 0 to size - 1
line_i = array.get(level_lines, i)
val_i = array.get(level_vals, i)
color_i = array.get(color_vals, i)
line.set_xy1(line_i, x = bar_index - 1, y = val_i)
line.set_xy2(line_i, x = bar_index, y = val_i)
line.set_color(line_i, color = color_i)
You can save the numbers in an array, then run a for loop in the array and plot dashed line at them. Example below
//#version=5
indicator(title="Plot numbers")
var numbers=array.from(3992.5,3990.25,3989,3987.25,3985,3983.25,3981,3977.25,3971.25,3966.5)
if barstate.isfirst
for i = 0 to array.size(numbers) - 1
line.new(bar_index, array.get(numbers,i),bar_index, array.get(numbers,i), style = line.style_dashed, color = color.black, extend = extend.both)

Tradingview Pinescript alert not working as expected

I am using below pinescript and i am not getting alerts as expected. I am aware that it is a repainting script. It is working fine with the back testing.
Long alert is set to "Once per bar close" and short alert is set to "once per bar".
The unexpected behavior is
1) Few times, i am getting short alert though there is no corresponding long alert (though i have taken care in my script, short alert will be sent only when there is a long).
2) Multiple consecutive Short alerts per bar. I am aware that in the realtime bar, the short condition may be true multiple number of times. But since i have set alert to "once per bar", the alert should come only for the first time short condition becomes true.
Please can you let me know if i am doing anything wrong ?
Thanks in advance.
//#version=4
study("My Script",overlay = true)
ST = input(true, title = "Activate Strategy Tester")
T_SY = input(2020, title = "Strategy Start Year")
T_SM = input(5, title = "Start Month")
T_SD = input(1, title = "Strategy Start Day")
T_EY = input(2025, title = "Strategy End Year")
T_EM = input(1, title = "End Month")
T_ED = input(1, title = "Strategy End Day")
T_S = timestamp(T_SY, T_SM, T_SD,00,00)
T_E = timestamp(T_EY, T_EM, T_ED,00,00)
T= ST and time >= T_S and time <= T_E
firstrun = true
bought = false
longcondition = false
shortcondition = false
//Just to track first run
firstrun := firstrun[1]
if (firstrun == false)
bought := bought[1]
//once condition is met, send a buy alert and make "bought" equal to true //to enable selling
if (close <= 8600 and bought==false and T)
bought := true
longcondition :=true
alertcondition(longcondition, "Long", "Long")
plotshape(longcondition, title = "Buy", text = 'Buy', style = shape.labelup, location = location.abovebar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)
if (longcondition)
longcondition :=false
//once condition is met, sent a sell alert.
if (bought and close>=9000 and T)
shortcondition := true
bought := false
alertcondition(shortcondition, "short", "short")
plotshape(shortcondition, title = "Sell", text = 'Sell', style = shape.labelup, location = location.belowbar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)
if (shortcondition)
shortcondition :=false
plotchar(bought, "bought", "", location = location.top)
firstrun := false
You bought variable now automatically saves its value bar to bar and I have removed the late reinitializations of vars in your script. Seems to be working fine here:
//#version=4
study("My Script",overlay = true)
ST = input(true, title = "Activate Strategy Tester")
T_SY = input(2000, title = "Strategy Start Year")
T_SM = input(5, title = "Start Month")
T_SD = input(1, title = "Strategy Start Day")
T_EY = input(2025, title = "Strategy End Year")
T_EM = input(1, title = "End Month")
T_ED = input(1, title = "Strategy End Day")
T_S = timestamp(T_SY, T_SM, T_SD,00,00)
T_E = timestamp(T_EY, T_EM, T_ED,00,00)
T= ST and time >= T_S and time <= T_E
var bought = false
longcondition = false
shortcondition = false
//once condition is met, send a buy alert and make "bought" equal to true //to enable selling
if (close <= 8600 and bought==false and T)
bought := true
longcondition :=true
//once condition is met, sent a sell alert.
if (bought and close>=9000 and T)
shortcondition := true
bought := false
alertcondition(longcondition, "Long", "Long")
alertcondition(shortcondition, "short", "short")
plotshape(longcondition, title = "Buy", text = 'Buy', style = shape.labelup, location = location.abovebar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)
plotshape(shortcondition, title = "Sell", text = 'Sell', style = shape.labelup, location = location.belowbar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)
// For debugging.
plotchar(bought, "bought", "•", location = location.top)
if buy signal is generated continuously for two sessions, then it will not appear till sell signal is generated.

Roblox ScreenGUI problems

I was wondering if there was a thing that I had to do in order to change the text of a GUI mid-game. Because my problem is that I'm making a timer that goes through "Round in progress", "Game Over", "Intermission", "Voting in progress," and then repeat forever. But the text itself gets stuck on Round In Progress. Throughout the timer, the text value in the properties of the label changes, but the text doesn't change on the screen GUI
I've been changing the text with the same method every time:
status.Text = "Game over"
then I'd have the timer go about 5 seconds before I change it again:
status.Text = "Intermission"
And so on in a loop...
This is the whole code:
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local minutesvalue = rep:WaitForChild("Minutes")
local secondsvalue = rep:WaitForChild("Seconds")
local minutes = 0 --minutes
local seconds = 11 --seconds
local status = game.StarterGui.Status:WaitForChild("Status")
while true do
status.Text = "Round In Progress"
minutesvalue.Value = minutes
secondsvalue.Value = seconds
repeat
if secondsvalue.Value <= 0 then
minutesvalue.Value = minutesvalue.Value - 1
secondsvalue.Value = 59
else
secondsvalue.Value = secondsvalue.Value - 1
end
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
status.Text = "Game Over!"
wait(5)
status.Text = "Intermission"
secondsvalue.Value = 15
repeat
secondsvalue.Value = secondsvalue.Value - 1
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
status.Text = "Voting In Progress"
secondsvalue.Value = 10
repeat
secondsvalue.Value = secondsvalue.Value - 1
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
status.Text = "Loading Map..."
end
The Timer and the Status are separate GUIs.
I separated it in the hope that it would work, but it didn't.
It's because you're doing it in the StarterGui, I'm sure, do it in the players PlayerGui so replace:
local status = game.StarterGui.Status:WaitForChild("Status")
with:
local status = players[plr].PlayerGui:WaitForChild("Status")
(Define plr)

How to change a textbox backcolor using an if statement?

I'm trying to block out the textbox if the user selects a specific value from the dropdown (combobox). I am trying to change the textbox backcolor based on the value in a specific combobox. I have created the code below and was able to get it to work, but it only works if I manually run the macro in vba. Can you please assist me with this problem. Thanks
Private Sub discqty_DropButtonClick()
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If combobox1.Value = "NON-CONFORMANCE" Then
Me.discqty.Value = ""
Me.discqty.BackColor = lngBlack
End If
If combobox1.Value = "BOM CHANGE" Then
Me.discqty.Value = ""
Me.discqty.BackColor = lngBlack
End If
If combobox1.Value = "WOC" Then
Me.discqty.Value = ""
Me.discqty.BackColor = lngBlack
End If
If combobox1.Value = "LOST PART" Then
Me.discqty.BackColor = lngWhite
End If
If combobox1.Value = "DAMAGE/DESTROYED" Then
Me.discqty.BackColor = lngWhite
End If
If combobox1.Value = "QA/QC ISSUE" Then
Me.discqty.BackColor = lngWhite
End If
Call netvalue
End Sub
You need to out the Color changing part into the combobox1_Change() Sub
Double-click the ComboBox and then paste this into the Private Sub ComboBox1_Change() Sub that comes up.
Private Sub ComboBox1_Change()
If ComboBox1.Value = "NON-CONFORMANCE" Then
Me.discqty.Value = ""
Me.discqty.BackColor = lngBlack
ElseIf ComboBox1.Value = "BOM CHANGE" Then
Me.discqty.Value = ""
Me.discqty.BackColor = lngBlack
ElseIf ComboBox1.Value = "WOC" Then
Me.discqty.Value = ""
Me.discqty.BackColor = lngBlack
ElseIf ComboBox1.Value = "LOST PART" Then
Me.discqty.BackColor = lngWhite
ElseIf ComboBox1.Value = "DAMAGE/DESTROYED" Then
Me.discqty.BackColor = lngWhite
ElseIf ComboBox1.Value = "QA/QC ISSUE" Then
Me.discqty.BackColor = lngWhite
End If
End Sub