Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my script "blink" every time I press space?

Asked by 6 years ago

I have a script that makes your screen turn black every couple of seconds. I want to be able to press space and make the script make the screen turn black. Anyone know how I could do this?

Script is here just in case ya need it.

  1. while true do
  2. wait(20)
  3. for i,player in pairs(game.Players:GetChildren()) do
  4. local s=Instance.new("ScreenGui")
  5. s.Parent=player.PlayerGui
  6. local t=Instance.new("Frame")
  7. t.Size=UDim2.new(2,0,2,0)
  8. t.Position=UDim2.new(-0.5,0,-0.5,0)
  9. t.BackgroundColor3=Color3.new(0,0,0)
  10. t.ZIndex=-1
  11. t.Parent=s
  12. delay(0.2,function() s:remove() end)
  13. end
  14. end

Any help?

0
Use a code block by clicking the Lua block and take off the "1." User#24403 69 — 6y
0
remove() is deprecated, use Destroy() DeceptiveCaster 3761 — 6y
0
also use the UserInputService for keyboard input DeceptiveCaster 3761 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

so according to your question, you want to press Space which would make the screen go black for a few secs aka blink

you gotta use UserInputService


local input = game:GetService("UserInputService") -- sets the userinput input.InputBegan:connect(function(Blink) --calls the function if Blink.KeyCode == Enum.KeyCode.Space then -- when u press space it triggers script wait(2) -- 20 secs is a lil to long so i moved it to 2 secs for i,player in pairs(game.Players:GetChildren()) do local s=Instance.new("ScreenGui") s.Parent=player.PlayerGui local t=Instance.new("Frame") t.Size=UDim2.new(2,0,2,0) t.Position=UDim2.new(-0.5,0,-0.5,0) t.BackgroundColor3=Color3.new(0,0,0) t.ZIndex=-1 t.Parent=s delay(0.2,function() s:Destroy() end) -- replaced remove to destroy end end end)

make sure its a local script that goes into StarterCharacterScripts.

your welcome.

(i also tried this myself and it works so, if you got any errors let me know)

0
Just saying the 20 seconds were for how long in between each "blink" was. Tyserkhan004 22 — 6y
0
But the script does work, Thank you. Tyserkhan004 22 — 6y
0
oh, you're welcome! A1exTatum 57 — 6y
Ad

Answer this question