#Need help finishing script, idk how to finish it

122 messages · Page 1 of 1 (latest)

forest mist
#

The first script was for a bindable event, ive changed it, i hope it isnt wrong, the second script is not edited, need help finishing it off (this script is to turn off a light at a certian clock time)

#
local bimdables = game:GetService("ServerStorage"):WaitForChild("Bindables")
local nightBegin = bimdables.NightBegin
local nightEnd = bimdables.NightEnd

local light1 = script.Parent.Light
local light2 = script.Parent.Light2

nightEnd.Event:Connect(function()
    print("e")
    light1.Color = Color3.fromRGB(19, 255, 208)
    light1.Light1.Enabled = false
    light2.Color = Color3.fromRGB(19, 255, 208)
    light2.SpotLight.SpotLight.Enabled = false
end)

nightBegin.Event:Connect(function()
    light1.Color = Color3.fromRGB(0, 0, 0)
    light1.Light1.Enabled = true
    light2.Color = Color3.fromRGB(0, 0, 0)
    light2.SpotLight.Enabled = true
end)

nightBegin.OnServerEvent:Connect(nightBegin)
nightEnd.OnServerEvent:Connect(nightEnd)
#
local bind = game:GetService("ServerStorage").Bindables
local nightStart = bind.NightBegin
local nightEnd    = bind.NightEnd
local ClockTime = game.Lighting.ClockTime

while task.wait(0.1) do
    if ClockTime >= 7.1 and ClockTime <= 7.2 then
        nightEnd:Fire()
    elseif ClockTime <= 18 and ClockTime >= 18.1  then
        nightStart:Fire()

    end

end
#

h

#

e

#

l

#

p

#

m

#

e

#

:)

shrewd matrix
#

whats bad

#

between why two bindableevents when can be one

#

and a bindable event doesnt receive a onserverevent

#

receives an "Event"

errant glacier
#

in the first script you were trying to connect the events to themselves. when using :Connect method, a function is required for it to work and from what i can see here nightBegin and nightEnd arent functions, theyre bindable events

fallow vineBOT
#

studio** You are now Level 5! **studio

forest mist
errant glacier
#

yes you never stated they were functions but

nightBegin.OnServerEvent:Connect(nightBegin) 
nightEnd.OnServerEvent:Connect(nightEnd) 

is incorrect because there is no nightBegin() or nightEnd() function but either way you dont have to type these because nightBegin.Event:Connect and nightEnd.Event:Connect should be already enough to work

forest mist
#

@errant glacier i can show the original script if you need to see it, it didnt work

errant glacier
#

yes thatd be appreciated

forest mist
#

@errant glacier i couldnt get the original script but i tried my best to get it to how it was (the remote events have been changed to bindables because thats how they were)

#
local bimdables = game:GetService("ServerStorage"):WaitForChild("Bindables")
local nightBegin = bimdables.NightBegin
local nightEnd = bimdables.NightEnd

local light1 = script.Parent.Light
local light2 = script.Parent.Light2

nightEnd.Event:Connect(function()
    print("e")
    light1.Color = Color3.fromRGB(19, 255, 208)
    light1.Light1.Enabled = false
    light2.Color = Color3.fromRGB(19, 255, 208)
    light2.SpotLight.SpotLight.Enabled = false
end)

nightBegin.Event:Connect(function()
    light1.Color = Color3.fromRGB(0, 0, 0)
    light1.Light1.Enabled = true
    light2.Color = Color3.fromRGB(0, 0, 0)
    light2.SpotLight.Enabled = true
end)
#
local bind = game:GetService("ServerStorage").Bindables
local nightStart = bind.NightBegin
local nightEnd    = bind.NightEnd
local ClockTime = game.Lighting.ClockTime

while task.wait(0.1) do
    if ClockTime >= 7.1 and ClockTime <= 7.2 then
        nightEnd:Fire()
    elseif ClockTime <= 18 and ClockTime >= 18.1  then
        nightStart:Fire()

    end

end
errant glacier
#

could you check light2.SpotLight.SpotLight.Enabled inside nightEnd.Event function?

#

maybe it could be light2.SpotLight.Enabled instead of that

forest mist
#

oh, yeah that flew right over me, that would be a problem

#

let me fix that

#

i fixed that, but it still wont turn on

errant glacier
#

hmm, no errors in the output either?

forest mist
#

no

errant glacier
#

hmm it could be because of the overcalling of events

forest mist
#

how could i avoid that?

errant glacier
#

firing events with a loop as fast as 0.1 secs could be affecting that

#

but

#

that doesnt matter

#

you just need a variable that will limit an event fire for 1 time

#

so

forest mist
#

in theory this script should be working

errant glacier
#

yes it should

forest mist
#

i could do that

#

let me add that real quick

forest mist
forest mist
#

alright

#

sorry about that, here is the script

#
local bind = game:GetService("ServerStorage").Bindables
local nightStart = bind.NightBegin
local nightEnd    = bind.NightEnd
local ClockTime = game.Lighting.ClockTime
local Variable = true

while task.wait(0.1) and Variable do
    if ClockTime >= 7.1 and ClockTime <= 7.2 then
        Variable = false
        nightEnd:Fire()
    elseif ClockTime <= 18 and ClockTime >= 18.1 and not Variable then
        nightStart:Fire()
        Variable = true
    end

end
errant glacier
#

o uh

forest mist
#

sorry if its wrong, im not great at scripting

errant glacier
#

nah its aight just gotta learn some stuff ykyk

#

so anyways

#

first off

forest mist
#

how would i fix the script

#

with the variable

errant glacier
#

yes exactly

#

but

#

wait

#

so

#

if you include the Variable in the while do statement with "and"

#

the while do loop will just loop once because Variable is defined as true

#

sooo okay

forest mist
#

ah

errant glacier
#

instead of using a while do loop

#

you should use a GetPropertyChangedSignal

#

its basically like an event but any change to a property of lighting will run the code

#

so that the events dont have to fire every 0.1 sec

#

instead they will fire upon changing the clocktime

forest mist
#

how would i change the script? this?

local bind = game:GetService("ServerStorage").Bindables
local nightStart = bind.NightBegin
local nightEnd    = bind.NightEnd
local ClockTime = game.Lighting.ClockTime
local Variable = true

GetPropertyCh and Variable do
    if ClockTime >= 7.1 and ClockTime <= 7.2 then
        Variable = false
        nightEnd:Fire()
    elseif ClockTime <= 18 and ClockTime >= 18.1 and not Variable then
        nightStart:Fire()
        Variable = true
    end

end
errant glacier
#

wait wait

#

leme teach ya

forest mist
#

wait some of the getproperty thing was cut off

#

ok

errant glacier
#

okay so first

#

we're not going to use clocktime variable

#

we just need the game.Lighting

#

to use the GetPropertyChangedSignal

#

it would be like this

#

game.Lighting:GetPropertyChangedSignal()

#

and wait its not done yet

#

inside the parenthesis we're going to insert which property thats going to be changed

#

in our case its clockTime

#

ClockTime

forest mist
#

ok

errant glacier
#

so game.Lighting:GetPropertyChangedSignal("ClockTime")

#

now we have an event when the property "ClockTime" gets changed then fires a code

#

we're just gonna connect it to a function so

#

this:

#
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()

end) 
#

oops

#

o wait nvm yea its correct

#

so its like that

forest mist
#

how would i fit the bindables inside of it

errant glacier
#

nono

#

i mean

#

uh im not sure what you mean

#

but

#

youre just going to use the same code that u used in the while loop

errant glacier
#

yea just copy and paste from if ClockTime ... to end

errant glacier
forest mist
#

im confused

errant glacier
#

o uh

#

wait

#
local bind = game:GetService("ServerStorage").Bindables
local nightStart = bind.NightBegin
local nightEnd    = bind.NightEnd
local ClockTime = game.Lighting.ClockTime
local Variable = true

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function() 
    if ClockTime >= 7.1 and ClockTime <= 7.2 then
        Variable = false
        nightEnd:Fire()
    elseif ClockTime <= 18 and ClockTime >= 18.1 and not Variable then
        nightStart:Fire()
        Variable = true
    end
end) 
#

there just like that

forest mist
#

do i paste that in

errant glacier
#

yea

#

but wait its not done yet

forest mist
#

ok

errant glacier
#

so uh i suggest u to rename Variable to isNight

forest mist
#

does it matter?

errant glacier
#

so like if its night then isNight = true

forest mist
#

i see

#

alright

errant glacier
#

well i mean it doesnt that much but

#

it helps to know what variables ur dealin with

forest mist
#

huh it didnt work

errant glacier
#

wait bru its not done yet lol

forest mist
#

ok

errant glacier
#

do u just want a script thats alr done or do u wanna learn how to do it

forest mist
#

im going to hold on for a second, because i feel sick at looking at a computer screen for a while, so can you explain how to do it and show the finished script at the end?

errant glacier
#

well aight

forest mist
#

thanks though, i appreciate it