#Zooming, and Mouse Scroll Wheel stuff

53 messages · Page 1 of 1 (latest)

kindred ice
#

the code is somewhat working because when i go ingame and scroll the mousewheel forward, it adds 1 to the range value of the flashlight, but only does it once, and never again when i scroll forward more

heavy surge
#

That means you did something wrong with the handling

#

can u show the code again or did you fifx it

kindred ice
#

i got it working now, but ill send you the portion that i got working to see if you can help me understand what couldve went wrong

#

i deleted the old code before you typed so i cant get it back

#

local function FlashlightToggle()
    if FlashL.Enabled == true then
        FlashL.Enabled = false
    elseif FlashL.Enabled == false then
        FlashL.Enabled = true
    end
end

local function ZoomingFORWARD()
    if FlashL.Range == FlashL.Range then
        FlashL.Range = math.clamp(FlashL.Range + add, 15, 60)
    end
end

local function ZoomingBACKWARD()
    if FlashL.Range == FlashL.Range then
        FlashL.Range = math.clamp(FlashL.Range - sub, 15, 60)
    end
end

-- Connecting --

UIS.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.F then
        FlashlightToggle()
    end
end)

Mouse.WheelForward:Connect(ZoomingFORWARD)
Mouse.WheelBackward:Connect(ZoomingBACKWARD)```
#

working code

#

im thinking it has to do with something i did in the "Flash.Range = math.clamp(FlashL.Range + add, 15, 60)", cuz i had variables set up for the default range of the light, which was a value instead of the actual property

heavy surge
#

Btw for the FlashlightToggle you can simplify and to "FlashL.Enabled = not FlashL.Enabled

#

pretty much short for "toggle != toggle"

kindred ice
#

i was thinking that!! thank you for helping ^^

kindred ice
heavy surge
#

i didnt see ur old code but you might of tried to add a value to the range instead of the actual property?

kindred ice
#

lemme try to recreate it

#
    if FlashL.Range == FlashL.Range then
        FlashL.Range = math.clamp(defRange + add, 15, 60)
    end
end```

for context, "defRange" is a variable i have set up to equal 15
#

and "add" is a variable equal to 1

heavy surge
#

yup

#

your add and defrange which is a constant value of 15. Which means no matter how much times u scroll with your mouse the flashl.range will always be clamped to a value between 15 and 16

kindred ice
#

yehh, i figured that out when i added the actual range property inplace of defRange

#

makes a looot more sense now

#

thank you so much!! <3

kindred ice
#

ok i might actually need help with something else now @heavy surge

heavy surge
#

yes?

kindred ice
heavy surge
#

have u tried tweening?

kindred ice
#

I'm trying to use Tweens to do that, but it's messing with the actual part of the code that changes the range, and makes it lose range (for some reason)

heavy surge
#

et me take a look at the code

kindred ice
#

-- Important --

local Mouse = Plr:GetMouse()

local FlashL = Instance.new("SpotLight")

local angle = 54
local defRange = 15

-- Flashlight Properties --

FlashL.Enabled = false
FlashL.Brightness = 2.2
FlashL.Range = defRange
FlashL.Angle = angle
FlashL.Shadows = true
FlashL.Parent = Head

-- Possible --

local Rangeadd = 2.8
local Rangesub = 2.8

local Angleadd = 6.7
local Anglesub = 6.7

local goal = {}
goal.Range = Rangeadd
goal.Range = Rangesub
goal.Angle = Angleadd
goal.Angle = Anglesub

local RangeADDtween = TS:Create(FlashL, TInfo, goal)
local RangeSUBtween = TS:Create(FlashL, TInfo, goal)

-- Functions --

local function FlashlightToggle()
    if FlashL.Enabled == true then
        FlashL.Enabled = false
    elseif FlashL.Enabled == false then
        FlashL.Enabled = true
    end
end

local function ZoomingFORWARD()
    if FlashL.Range == FlashL.Range then
        RangeADDtween:Play()
        FlashL.Range = math.clamp(FlashL.Range + Rangeadd, 32, 60)
        if FlashL.Angle == FlashL.Angle then
            FlashL.Angle = math.clamp(FlashL.Angle - Anglesub, 27, 90)
        end
    end
end

local function ZoomingBACKWARD()
    if FlashL.Range == FlashL.Range then
        RangeSUBtween:Play()
        FlashL.Range = math.clamp(FlashL.Range - Rangesub, 32, 60)
        if FlashL.Angle == FlashL.Angle then
            FlashL.Angle = math.clamp(FlashL.Angle + Angleadd, 27, 90)
        end
    end
end```
#

i might know why, but im not too sure either

heavy surge
#
local TweenService = game:GetService("TweenService")
local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Head = Plr.Character.Head

local FlashL = Instance.new("SpotLight", Head)
FlashL.Enabled = false
FlashL.Brightness = 2.2
FlashL.Range = 15
FlashL.Angle = 54
FlashL.Shadows = true

local TInfo = TweenInfo.new(2, Enum.EasingStyle.Linear)

local Rangeadd = 2.8
local Rangesub = 2.8
local Angleadd = 6.7
local Anglesub = 6.7

-- Functions --

local function FlashlightToggle()
    if FlashL.Enabled == true then
        FlashL.Enabled = false
    elseif FlashL.Enabled == false then
        FlashL.Enabled = true
    end
end

local function ZoomingFORWARD()
    local goal = {}
    goal.Range = math.cl(ampFlashL.Range + Rangeadd, 32, 60)
    goal.Angle = math.clamp(FlashL.Angle - Anglesub, 27, 90)

    local tween = TweenService:Create(FlashL, TInfo, goal)
    tween:Play()
end

local function ZoomingBACKWARD()
    local goal = {}
    goal.Range = math.clamp(FlashL.Range - Rangesub, 32, 60)
    goal.Angle = math.clamp(FlashL.Angle + Angleadd, 27, 90)

    local tween = TweenService:Create(FlashL, TInfo, goal)
    tween:Play()
end
#

You can try this

kindred ice
#

yeh youre not wrong, i js would like it to be a bit smoother

stone muskBOT
#

studio** You are now Level 4! **studio

kindred ice
#

btw it works, thx!

#

and im pretty sure i understand too!

heavy surge
#

The tween will always use the value of the FlashL.Range and FlashL.Angel when it starts then it will tween towards the goal values

kindred ice
#

yehhh thats what i was thinking after seeing that, i forgot it actually messes with the values

#

anyways im gonna try and finish the rest of this flashlight! ill let yk if i need help with anything ^^

kindred ice
#

so i might need help with 2 small things @heavy surge you ok with that?

heavy surge
#

sure

kindred ice
#

alr gimme a sec

#

hello?

#

ah there we go

#

smt weird happened lol

heavy surge
#

you can add a toggle for it

#

like when the flashlight is on it will turn off and go to blacklight

#

when blacklight is on it turns off and flashlight turns on

kindred ice
#

Yeh that's what I'm trying to do, do you wanna see what I've got with it

#

*?