How to get a NumberValue to update outside of ClickDetector


I’m trying to make a way for the player to edit the length of the tween, using the numbered buttons below.


Each button changes the NumberValue in Explorer.
However, when the tween is run, it uses the value that the game started with, which is 5.

I can’t use ClickDetectors to update the value, because there’s already an OnClicked function later in the script, and it would only needlessly complicate things to add another OnClicked function.

Thanks in advance.

Just add do Num = Num + 1? I don’t understand what you mean.

Sorry, it’s kinda hard to explain.

I’m trying to create a feature that allows the player to configure the length of the tween, remotely with the buttons showcased in the post.

The problem is: when the tween is run, it neglects the NumberValue that was changed, and just uses the original value.

Not sure if that helps.

Number.value? Is that what tour doing?

No. The instance “NumberValue”, not Number.Value

Ok, what I would do is make a number value object outside of the script and that number is the value you use.

But that’s exactly what I did?
2020-05-23 (7)

Are you doing value.value. Please show full script.

local tweenService = game:GetService("TweenService")

local part1 = game.Workspace.light1.PointLight

local part2 = game.Workspace.light2.PointLight

local part3 = game.Workspace.light3.PointLight

local part4 = game.Workspace.light4.PointLight

local part5 = game.Workspace.light5.PointLight

local part6 = game.Workspace.light6.PointLight

local part7 = game.Workspace.light7.PointLight

local part8 = game.Workspace.light8.PointLight

local part9 = game.Workspace.light9.PointLight

local part10 = game.Workspace.light10.PointLight

local part11 = game.Workspace.light11.PointLight

local part12 = game.Workspace.light12.PointLight

local part13 = game.Workspace.light13.PointLight

local part14 = game.Workspace.light14.PointLight

local part15 = game.Workspace.light15.PointLight

local part16 = game.Workspace.light16.PointLight

local part17 = game.Workspace.light17.PointLight

local part18 = game.Workspace.light18.PointLight

local part19 = game.Workspace.light19.PointLight

local part20 = game.Workspace.light20.PointLight

local part21 = game.Workspace.light21.PointLight

local part22 = game.Workspace.light22.PointLight

local part23 = game.Workspace.light23.PointLight

local part24 = game.Workspace.light24.PointLight

local part25 = game.Workspace.light25.PointLight

local part26 = game.Workspace.light26.PointLight

local part27 = game.Workspace.light27.PointLight

local part28 = game.Workspace.light28.PointLight

local part29 = game.Workspace.light29.PointLight

local part30 = game.Workspace.light30.PointLight

local part31 = game.Workspace.light31.PointLight

local part32 = game.Workspace.light32.PointLight

local part36 = game.Workspace.panel1

local part37 = game.Workspace.panel2

local part38 = game.Workspace.panel3

local part39 = game.Workspace.panel4

local part40 = game.Workspace.panel5

local part41 = game.Workspace.panel6

local part42 = game.Workspace.panel7

local part43 = game.Workspace.panel8

local part44 = game.Workspace.panel9

local part45 = game.Workspace.panel10

local part46 = game.Workspace.slight1.PointLight

local part47 = game.Workspace.slight2.PointLight

local part48 = game.Workspace.slight3.PointLight

local part49 = game.Workspace.set.partial1

local part50 = game.Workspace.set.partial2

local part51 = game.Workspace.set.partial3

local part52 = game.Workspace.set.partial4

local part53 = game.Workspace.set.partial5

local part54 = game.Workspace.set.partial6

local part55 = game.Workspace.set.partial7

local part56 = game.Workspace.set.partial8

local part57 = game.Workspace.set.partial9

local part58 = game.Workspace.set.partial10

local part59 = game.Workspace.set.partial11

local part60 = game.Workspace.set.partial12

local part61 = game.Workspace.set.partial13

local part62 = game.Workspace.set.partial14

local part63 = game.Workspace.set.partial15

local part64 = game.Workspace.set.partial16

local part65 = game.Workspace.set.partial17

local part66 = game.Workspace.set.partial18

local part67 = game.Workspace.set.partial19

local part68 = game.Workspace.set.wash1

local part69 = game.Workspace.set.wash2

local part70 = game.Workspace.set.wash3

local part71 = game.Workspace.set.wash4

local part72 = game.Workspace.panel11

local part73 = game.Workspace.panel12

local part74 = game.Workspace.floor1

local part75 = game.Workspace.floor2

local part76 = game.Workspace.floor3

local part77 = game.Workspace.floor4

local part78 = game.Workspace.floor5

local part79 = game.Workspace.floor6

local part80 = game.Workspace.floor7

local part81 = game.Workspace.floor8

local part82 = game.Workspace.floor9

local part83 = game.Workspace.floor10

local part84 = game.Workspace.floor11

local part85 = game.Workspace.floor12

local part86 = game.Workspace.floor13

local part87 = game.Workspace.floor14

local part88 = game.Workspace.floor15

local part89 = game.Workspace.floor16

local part90 = game.Workspace.floor17

local part91 = game.Workspace.floor18

local part92 = game.Workspace.floor19

local part93 = game.Workspace.floor20

local part94 = game.Workspace.floor1.SurfaceLight

local part95 = game.Workspace.floor5.SurfaceLight

local part96 = game.Workspace.floor9.SurfaceLight

local part97 = game.Workspace.floor12.SurfaceLight

local part98 = game.Workspace.floor16.SurfaceLight

local part99 = game.Workspace.floor20.SurfaceLight

local memory = game.Workspace.memoryA1.Color

local memory2 = game.Workspace.memoryB1.Color

local tweeningInformation = TweenInfo.new(

game.Workspace.A.Value.Value, -- Length

Enum.EasingStyle.Linear, -- easing style of the TweenInfo

Enum.EasingDirection.Out, -- easing direction of the TweenInfo

0, -- number of times the tween will repeat

false, -- should the tween repeat?

0 -- delay between repeats

)

local partProperties = {

Color = Color3.fromRGB(memory);

}

local partProperties = {

Color = Color3.fromRGB(memory2);

}

local Tween = tweenService:Create(part1,tweeningInformation,partProperties)

local function onClick()

local partProperties = {

Color = workspace.memoryA1.Color;

}

local partProperties2 = {

Color = workspace.memoryB1.Color;

}

local partProperties3 = {

Color = workspace.memoryC1.Color;

}

local partProperties4 = {

Color = workspace.memoryD1.Color;

}

local t = tweenService:Create(part1,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part2,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part3,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part4,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part5,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part6,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part7,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part8,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part9,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part10,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part11,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part12,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part13,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part14,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part15,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part16,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part17,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part18,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part19,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part20,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part21,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part22,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part23,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part24,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part25,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part26,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part27,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part28,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part29,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part30,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part31,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part32,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part36,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part37,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part38,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part39,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part40,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part41,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part42,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part43,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part44,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part45,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part46,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part47,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part48,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part49,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part50,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part51,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part52,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part53,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part54,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part55,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part56,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part57,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part58,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part59,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part60,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part61,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part62,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part63,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part64,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part65,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part66,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part67,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part68,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part69,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part70,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part71,tweeningInformation,partProperties2)

t:Play()

local t = tweenService:Create(part72,tweeningInformation,partProperties)

t:Play()

local t = tweenService:Create(part73,tweeningInformation,partProperties4)

t:Play()

local t = tweenService:Create(part74,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part75,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part76,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part77,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part78,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part79,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part80,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part81,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part82,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part83,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part84,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part85,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part86,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part87,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part88,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part89,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part90,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part91,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part92,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part93,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part94,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part95,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part96,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part97,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part98,tweeningInformation,partProperties3)

t:Play()

local t = tweenService:Create(part99,tweeningInformation,partProperties3)

t:Play()

end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

Here it is. The heap of convoluted garbage.
(To answer your question, I’m pretty sure I am using value.value)

Ok you could just use a for loop or collection service to shorten thy to 20 lines.

I’m not looking to shorten anything. Just here to fix my problem.

Does making a loop help my problem?

That would fix the problem. Trust me you will find out short code makes things so much easier. Use collection service and get tagged then run the tween on click and update the tween info as the prior script was saved to “memory” you need to update it with the value. I suppose you could also try and get property change signal in and put the value to check if the value is updated and then run the tween service.

One solution is to put the “tweeningInformation” variable inside the onClick() function.

When you define the variable if sets the value to the current state of time.
This value will never change until you re-define it again.

local TimeOfDay = game.Lighting:GetMinutesAfterMidnight()
print(TimeOfDay) -- returns 840
wait(5)
print(TimeOfDay) -- returns 840

Here when I print the variable at the beginning it gives me the same value as when I print the variable 5 seconds later. Because nothing has changed the value again.

local TimeOfDay = game.Lighting:GetMinutesAfterMidnight()
print(TimeOfDay) -- returns 840
wait(5)
TimeOfDay = game.Lighting:GetMinutesAfterMidnight()
print(TimeOfDay) -- returns 900

Shortening it won’t fix the problem, it will be a lot easier to read though. You could put all parts inside a table then iterate through all of them.

local Lights = {game.Workspace.light1.PointLight, game.Workspace.light2.PointLight, ...}

for i = 1, #Lights do
    tweenService:Create(Lights[i], tweeningInformation, partProperties):Play()
end
2 Likes

or that. I couldn’t read the code because it’s over complicated.

I would use collection service as it is just as simple as getting the tagged. Then once you get the tagged you run the tween as I mentioned before. I’m also on my phone so I can’t type code blocks out. Sorry I wasn’t much help.

Yeah, sorry about that. I’m not a great scripter, so my way of doing things is always really complicated, and it’s always hard getting help from developers because my scripts always puzzle them, and it’s embarrassing.

I appreciate you trying to work with me though!

2 Likes

Collection service works wonders. I had 500 lines of code narrowed to 30 in a game I was working on. It was amazing to see what one little tag can do. I can link you the plugin if you would like to use it?

1 Like

Don’t worry about it! You’re doing great, eventually you’ll get to the point where you write code cleanly. Don’t be afraid to ask questions, everyone here on the forums wants to help you!

2 Likes

Yes, I agree I started lua little over 2 weeks ago and trust me dev forums worked wonders for my development as a scripter. However My code is still messy i want to get there eventually.

1 Like