I started scripting around two months ago and decided to start branching out. For my first task, I decided to make a run button, and when the player runs, the game's brightness would increase, however, I need help, as it is not working and no errors are appearing in the output.
l--Player-- local Player = game.Players.LocalPlayer local character = Player.Character if not character or not character.Parent then character = Player.CharacterAdded:wait() end --Services/Other-- local mouse = game.Players.LocalPlayer:GetMouse() --Variables-- local Head = character["Head"] local LeftArm = character["Left Arm"] local LeftLeg = character["Left Leg"] local RightArm = character["Right Arm"] local RightLeg = character["Right Leg"] local Torso = character.Torso --Functions-- function getTool() for _, kid in ipairs(script.Parent:GetChildren()) do if kid.className == "Tool" then return kid end end return nil end mouse.KeyDown:connect(function (key) key = string.lower(key) if string.byte(key) == 107 then running = true local keyConnection = mouse.KeyUp:connect(function (key) if string.byte(key) == 108 then running = false end end) for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (70+(i*2)) wait() end game:GetService("Chat"):Chat(Head, "Clock Up...", Enum.ChatColor.Red) game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 150 game.Players.LocalPlayer.Character.Humanoid.JumpPower = 65 LeftLeg.BottomSurface = "Glue" RightLeg.BottomSurface = "Glue" repeat wait(99999999999999999999999999999999999999999) until running == false keyConnection:disconnect() game:GetService("Chat"):Chat(Head, "Clock Over...", Enum.ChatColor.Red) game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50 LeftLeg.BottomSurface = "Smooth" RightLeg.BottomSurface = "Smooth" for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) wait() end end end) --Local Functions-- function brightUp() if running == true then game.Lighting.Brightness = 2 if running == false then game.Lighting.Brightness = 1 end end end game.Lighting.LightingChanged:connect(brightUp)
If more code is needed, just ask!
Well if you make the script wait 99999999999999999999999999999999999999999 until it's allowed to check if running == false then you're gonna have to wait 99999999999999999999999999999999999999999 seconds before it prints anything too!
repeat wait(99999999999999999999999999999999999999999) until running == false --If you're just yielding until running == false you should drop that timer to something smaller...
Also, you can have KeyUp events to turn running off instead of waiting for disconnect events, it's how I do my own sprinting systems.
local function brightUp() if running == true then game.Lighting.Brightness = 2 if running == false then game.Lighting.Brightness = 1 end end end brightUp()