function CheckAndChange(player: Player, AppliedText)
if type(tonumber(AppliedText)) == "number" then
game.Lighting.ClockTime = AppliedText
else
warn("Text Must be a Number!")
return
end
end
RemoteFunction.OnServerInvoke = CheckAndChange
script.Parent.MouseButton1Click:Connect(function()
local Text = script.Parent.Parent.TextBox.Text
RemoteFunction:InvokeServer(Text)
end)
I think that’s really complicated and there’s a much easier way to do this, only with one remote event:
LocalScript(TextLabel is your timer and remoteevent is a remoteevent inside ReplicatedStorage:)
local remoteevent = game.ReplicatedStorage.TimerEvent
remoteevent.OnClientEvent:Connect(function(min,sec)
if sec < 10 then
script.Parent.TextLabel.Text = min..":0"..sec
else
script.Parent.TextLabel.Text = min..":"..sec
end
if min == 0 and sec == 1 then
script.Parent.TextLabel.Text = "Time's up!"
wait(math.huge)
end
end)
Script in ServerScriptService
local remoteevent = game.ReplicatedStorage.TimerEvent
local b = false
local min = 20
local sec = 59
while b = false do
sec = sec - 1
if sec <= 0 then
min = min - 1
sec = 59
end
if sec == 1 and min == 0 then
remoteevent:FireAllClients(min, sec)
wait(math.huge)
else
remoteevent:FireAllClients(min,sec)
task.wait(1)
end
end
Also this is just something I wrote on my phone so i give no guarentee that this actualky works. If there is any errors please feel free to tell me!
Not really, I dont think its complicated, i just dont think you are understanding the code:
function CheckAndChange(player: Player, AppliedText)
if type(tonumber(AppliedText)) == "number" then -- Checks if the given text is a number and can be converted to one
game.Lighting.ClockTime = AppliedText -- if so, it Applies it
else -- if isnt a number and cant be converted
warn("Text Must be a Number!")
return -- Ends function
end
end
print(type(10)) -- number
print(type(true)) -- boolean
print(type("Hello!")) -- string
print(type({"Hi"})) -- table
if type(100) == "number" then -- checks if 100 is a number
print("Yes")
end
so is tonumber and tostring
local StringNumber = "1"
local NewNumber = tonumber(StringNumber)
print(type(NewNumber)) -- Should return as a number
print(NewNumber)
local Number = 7384109
local NewString = tostring(Number)
print(type(NewString)) -- Should return as a string
print(NewString)
Thats not what they are trying to do, They aren’t trying to create a Timer, but simply change the time via TextBox, if you read the Topic, you would know