I made a GUI where you enter the time you want it to be in MinutesAfterMidnight. but whenever i hit the enter button, it says "Unable to cast string to double" and I can't seem to find out what it means simply by googling it. Can someone explain what this means and maybe a fix?
✓ ANSWER ACCEPTED
"Unable to cast string to double"?
1 answer
✓ Accepted answer
Your problem is that game.StarterGui.ScreenGui.TextBox.Text is a string type, meaning it is text. SetMinutesAfterMidnight. An easy fix is to type tonumber(game.StarterGui.ScreenGui.TextBox.Text).
However, that is not your only problem
Another problem I encountered is this: game.StarterGui.ScreenGui.TextBox
When players edit the textbox in their Gui, it is edited in game.Players.LocalPlayer.PlayerGui, and not game.StarterGui, therefore, you will have to set your code to this:
script.Parent.MouseButton1Click:Connect(function()
print("clicked")
game.Lighting:SetMinutesAfterMidnight(tonumber(game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox.Text))
print("entered")
end)
You may be like "Wait a minute, this is super complex code"!
You can actually tidy this up with variables
local SetTimeButton = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local MinutesAfterMidnightInput = Player.PlayerGui.ScreenGui.TextBox
local Lighting = game:GetService("Lighting")
SetTimeButton.Activated:Connect(function()
print("Clicked!")
Lighting:SetMinutesAfterMidnight(tonumber(MinutesAfterMidnightInput.Text))
print("Set time successfully!")
end)
Edit 1: Fixed error I just noticed
3 comments
0
thanks!
0
it works!
0
No problem!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Post your code?
@TTChaos script.Parent.MouseButton1Click:Connect(function() print("clicked") game.Lighting:SetMinutesAfterMidnight(game.StarterGui.ScreenGui.TextBox.Text) print("entered") end)