Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clicking a part to change the time is not working?

Asked by 4 years ago

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?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Problem

Clicking a part to change the time is not working?

Solution

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)

1
Right, thank you for the answer. Cyroxite 46 — 4y
0
You're welcome :3 EpicMetatableMoment 1444 — 4y
Ad

Answer this question