I am just trying to understand why one works and the other doesn’t because to me, it’s the same code just written sightly different.
uis.InputBegan:Connect(function(input, proc)
if proc then return end
if input.KeyCode == Enum.KeyCode.M then
local time = game.Lighting.TimeOfDay
time = "22:00:00"
print("M pressed!")
end
end)
uis.InputBegan:Connect(function(input, proc)
if proc then return end
if input.KeyCode == Enum.KeyCode.M then
game.Lighting.TimeOfDay = "22:00:00"
print("M pressed!")
end
end)
actually youre wrong if you looked at screenshots i have sent above you would know that
when you do a time = game.Lighting.TimeOfDay you just asigning the value to a variable and changing the value thats asigned to variable won’t apply changes to the actual instance
The problem is that Lua passes every type except function , table , userdata, thread and some other Luau built ins on Roblox by value and not by reference. This means the code in your first example actually copies the value of game.Lighting.TimeOfDay and then writes it to the variable time. Your variable time has no correlation with the variable game.Lighting.TimeOfDay and you can write to both independently. Running time = "22:00:00" will set the value of the variable time to “22:00:00” but keep game.Lighting.TimeOfDay unchanged as the two are separate variables.
--The string type is passed by value
local var1 = "Hello"
local var2 = var1
var2 = "World"
print(var1) --Prints "Hello"
print(var2) --Prints "World"
--The table type is passed by reference
local var1 = {"Hello"}
local var2 = var1
var2[1] = "World"
print(var1[1]) --Prints "World"
print(var2[1]) --Prints "World"
Actually I’m not wrong … I know you can set a variable to most anything in lha.
The thing is this is still a command and it’s general knowledge not to use key words
in any language. This is a great way to set yourself up for hidden errors that make no sense.
Like I said, you can use Time with a capital T. Also, I’m not looking for a debate.
Now as for your real problem with the 1st function.
When you set up variables for use later on, you can not also include parameters.
In the line: local Time = game.Lighting.TimeOfDay … TimeOfDay is a parameter in lighting.
You just want Lighting, then add whatever parameter when you call it.
Like this:
local Time = game.Lighting
Time.TimeOfDay = "22:00:00"
“Next time” understand you’re talking to a programmer of 45 years. Lha is just one language of many. It’s best to learn and use standards. Lha is one of the very few that is so forgiving.
You may want to work on your tact before you try to reply to someone. That was just over the top rude. Now we will see where your morals are… You and I both know this is the solution to your question… The advice was free.