Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

3 comments

0

Use a code block by clicking the Lua block and take off the "1."

0

remove() is deprecated, use Destroy()

0

also use the UserInputService for keyboard input

1 answer

✓ Accepted answer

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)

3 comments

0

Just saying the 20 seconds were for how long in between each "blink" was.

0

But the script does work, Thank you.

0

oh, you're welcome!

This discussion is preserved as it was. New answers, comments, and votes are closed.