“Team” and “TeamChecker” and local script “Team” not needed care it.
Looks good, just replace wait
with task.wait
and look into using a table and a ipairs
loop to gradually change the value instead of having 20 lines, I can help with this if you like (would take like 1 minute).
Nice, thanks!
It works!
But can you help me with how it can cooldown before enabling that once again, I don’t like that can be spamming
Just add a isTweening
value, make it true when starting the change, make it false after the change is done (or after a certain amount of time after the change is done), then check if isTweening is equal to false when doing the function.
Here’s the complete code, including implementing the table loop and task.wait
.
local stepsOn = {
-1, 0.5, -0.9, 0.05, -0.8, 0.01, -0.7, 0.01, -0.6, 0.01, -0.5, 0.01, -0.4, 0.01,
-0.3, 0.01, -0.2, 0.01, -0.1, 0.01, 0, 0.01, 0.1, 0.01, 0.2, 0.01, 0.3, 0.01,
0.4, 0.01, 0.5, 0.01, 0.6, 0.01, 0.7, 0.01, 0.8, 0.01, 0.9, 0.01, 1, 0.01
}
local stepsOff = {-0.7, 0.1, -0.8, 0.05, -0.9, 0.03, -1, 0.01}
local function onButtonActivated()
if isTweening then
return
end
isTweening = true
if toggled == false then
cc.Enabled = true
nvgsound:Play()
for i = 1, #stepsOn, 2 do
cc.Contrast = stepsOn[i]
task.wait(stepsOn[i + 1])
end
toggled = true
else
for i = 1, #stepsOff, 2 do
cc.Contrast = stepsOff[i]
task.wait(stepsOff[i + 1])
end
cc.Enabled = false
toggled = false
end
isTweening = false
end
local button = script.Parent
local nvgscreen = button.Parent.ImageLabel
local toggled = false
local nvgsound = workspace.NightVisionSound
local function onButtonActivated()
print("button pressed")
local cc = game.Lighting.ColorCorrection2
if not toggled then
cc.Enabled = true
nvgsound:Play()
for i = -1, 1, 0.1 do
wait(0.01)
game.Lighting.ColorCorrection2.Contrast = i
end
toggled = true
else
game.Lighting.ColorCorrection2.Contrast = -0.7
wait(0.1)
game.Lighting.ColorCorrection2.Contrast = -0.8
wait(0.05)
game.Lighting.ColorCorrection2.Contrast = -0.9
wait(0.03)
game.Lighting.ColorCorrection2.Contrast = -1
wait(0.01)
cc.Enabled = false
toggled = false
end
end
button.Activated:Connect(onButtonActivated)
I’m sorry, but this code isn’t efficient at all. Try something like this.
local TweenService = game:GetService("TweenService")
local currTween: Tween | nil = nil
local function cancelCurrentTween()
if currTween then
currTween:Pause()
currTween:Destroy()
currTween = nil
end
end
local function onButtonActivated()
cc.Enabled = not toggled
if toggled == false then
nvgsound:Play()
cancelCurrentTween()
currTween = TweenService:Create(cc, TweenInfo.new(.2, Enum.EasingStyle.Linear), {Contrast = 1})
currTween:Play()
else
cancelCurrentTween()
cc.Contrast = -.7
currTween = TweenService:Create(cc, TweenInfo.new(.19, Enum.EasingStyle.Linear), {Contrast = -1})
currTween:Play()
end
toggled = not toggled
end
button.Activated:Connect(onButtonActivated)
UserInputSerivce.InputBegan:Connect(function(input, chatting)
if chatting then return end
if input.KeyCode == Enum.KeyCode.E then
onButtonActivated()
end
end)
THANKS TO EVERYONE HERE WAS HELP ME, A FEW DAYS LATER YOU GUYS WILL GET A SURPRISE SPECIAL!
@roblox57ro_2 @0ffxInventor @GuySalami @jasperagent_dev @iATtaCk_Noobsi