Reputation: 43
I am trying to make a script, in Lua code, that detects the level of lighting in my game. I am pretty new to Lua so as far as I know lighting in the game is a number (2, 10, 5).
if game:GetService("Lighting").Brightness < 1 then
game.StarterGui.ScreenGui.output.Text = "You are getting cold";
end
I am not sure if it is just not detecting game:GetService("lighting").Brightness
as a number or if the game does not know what game.StarterGui.ScreenGui.output.Text
is. I've testing this multiple times, making small alteration every time, but most of the time I got no error. With the code now there is no error message.
Upvotes: 0
Views: 317
Reputation: 23
Do not use game.StarterGui. StarterGui is what gui is put inside a player's PlayerGui when they join. Players do NOT see StarterGui. Instead:
game.Players.PlayerAdded:Connect(function(plr)
if game:GetService("Lighting").Brightness < 1 then
plr.PlayerGui.ScreenGui.output.Text = "You are getting cold";
end
end)
(player).PlayerGui is the gui the player sees. StarterGui will not auto update or modify the game's players' guis when it is changed. If you have any more questions feel free to ask them with a comment! ^-^
Roblox lua documentation: https://www.developer.roblox.com/en-us
Upvotes: 2