So I made a Gui where if you click a button the time will be set to 8 pm. Since this is a localscript put into the Gui, I'm going to need a remote event. So I put it in ReplicatedStorage and put the script in ServerScriptService.
Here's the code for the localscript:
local button= game.StarterGui.ScreenGui.TextButton local minutesaftermidnight= (20 * 60) button.MouseButton1Down:Connect(function() game.ReplicatedStorage.LightingReplicator:FireServer(minutesaftermidnight) end)
Here's the code for the Server Script:
game.ReplicatedStorage.LightingReplicator.OnServerEvent:Connect(function(player,timegiven) game.Lighting:SetMinutesAfterMidnight(timegiven) end)
I've been adjusting things and it still won't work, and the output won't show any errors. Why does this happen?
Clicking a part to change the time is not working?
This occurs because you're referencing button
via StarterGui
. However a player's current UI is stored in PlayerGui
. The PlayerGui
folder is located inside the player's instance.
You should do something like where you index the PlayerGui
to reference the client's current UI. The :WaitForChild
I am using here is in case the code runs before the GUI exists so the code does not error!
https://developer.roblox.com/ko-kr/api-reference/function/Instance/WaitForChild
local players = game:GetService("Players") local client = players.LocalPlayer local playerGui = client:WaitForChild("PlayerGui") local screenGui = playerGui:WaitForChild("ScreenGui") local textButton = screenGui:WaitForChild("TextBox") textButton.MouseButton1Down:Connect(function() --// and so on end)