Currently having a problem where a button from a client side GUI is meant to stop a day/night cycle through the server with a remote event.
-- Client
local Button = script.Parent
ButtonTrue = false
Debounce = true
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.TimeCycle
function ButtonOff ()
-- When the button is turned off.
remoteEvent:FireServer()
print("Button Turned Off")
end
function ButtonOn ()
-- When the button is turned on.
remoteEvent:FireServer()
print("Button Turned On")
end
if Debounce then
Debounce = false
Button.MouseButton1Down:Connect(function()
if ButtonTrue == false then
ButtonTrue = true
Button.Parent.Button:TweenPosition(UDim2.new(0, 14,0, 13), "Out", "Linear", .1)
Button.Parent.BackgroundColor3 = Color3.new(0.8, 0.8, 0.8)
ButtonOff()
else
ButtonTrue = false
Button.Parent.Button:TweenPosition(UDim2.new(0, 25,0, 13), "Out", "Linear", .1)
Button.Parent.BackgroundColor3 = Color3.new(0, 0.792157, 0.305882)
ButtonOn()
end
end)
wait(Debounce)
Debounce = true
end
-- Server
local lighting = game:GetService("Lighting")
local minsAfterMidnight = 0
local daylength = 0.1
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.TimeCycle
pause = false
remoteEvent.OnServerEvent:Connect(function()
if pause == false then
pause = true
else
pause = false
end
end)
while true do
wait()
if pause == true then
print("Cycle Stopped.")
else
while true do
minsAfterMidnight = minsAfterMidnight + 1
local minutesNormalised = minsAfterMidnight % (60 * 24)
local hours = minutesNormalised / 60
lighting.ClockTime = hours
wait()
end
end
end
The main problem is that I’m not even getting an error so I’m not really sure what I’m doing wrong.