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

A Arithmetic error i guess again with lighting 'Ambient'?

Asked by 6 years ago

Basicly a error with the script so i am making a power switch for a computer core game and kinda guessed it errored due to the arithmetic on field of 'Ambient for the full script




cd = script.Parent.ClickDetector bool = true M_A_D = 0 M_A_D = cd.MaxActivationDistance offline = script.Parent.Offline cd.MouseClick:connect(function() if bool == true then bool = false cd.MaxActivationDistance = 0 for n = 1,87 do wait() script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-0.01) end wait() workspace.PowerOn:Play() workspace.ReactorOnline:Play() wait(2.585999999999999) for n = 1,70 do wait() game.Lighting.Ambient = game.Lighting.Ambient * Color3.new(1,1,1) end cd.MaxActivationDistance = M_A_D script.Parent.Off.Disabled =true script.Disabled = true end end)
0
Pretty much try to help me Animescapetower 10 — 6y
0
Accept the answer Shawnyg 4330 — 6y
0
I Did Animescapetower 10 — 6y

2 answers

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
6 years ago
Edited 6 years ago

Few flaws in your coding but nothing hard to fix.

First being... indenting.

local clickDetector = script.Parent.ClickDetector

--The proper term you're using this bool variable is called debounce.
local debounce = true

-- Use some proper variable names. Saves you the trouble of having to hold two buttons for an underscore.
local maxActivationDistance = clickDetector.MaxActivationDistance
local setActivationDistance = 50

local offline = script.Parent.Offline

clickDetector.MouseClick:Connect(function()
    if debounce == true then
        debounce = false
        maxActivationDistance = 0 

        --Why does this need to loop count to 87?
        for i = 1, 87, 1 do
            wait()
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-0.01)
        end

        wait()

        --Sounds?
        workspace.PowerOn:Play()
        workspace.ReactorOnline:Play()

        wait(2.6) --Is there a reason why this can't be simple, maybe 2.6?

        --I'm guessing you're wanting to make the lighting turn white?
        --No reason to loop up to 70 or multiply current lighting by a Color3. 
        --Instead use 'n' to go up in the Color3 values.
        for n = 0, 1, .01 do
            game.Lighting.Ambient = Color3.new(n,n,n)
            wait()
            --This loops after 1/30th a second and adds .01 to Ambient values.
        end

        clickDetector.MaxActivationDistance = setDistance

        script.Parent.Off.Disabled = true
        script.Disabled = true
    end
end)

Edit:

I had overlooked the changes to the MaxActivationDistance property for ClickDetector. You can have a variable in your script which you can freely change to any number. What you had would keep MaxActivationDistance always set to 0.

Ad
Log in to vote
0
Answered by 6 years ago

Thank you actually ehm.

0
Accept answer and upvote. xPolarium 1388 — 6y

Answer this question