Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is it possible to make the time of day change by chatting a keyword?

I am trying to make a script that changes the time of day when a player types a keyword in the chat, but I am not having much luck. Can someone please help?

Also is it possible for the time of day to only change on one player's screen, while it stays the same on everyone else's?

1 comment

0

Might be lemme check

2 answers

Yes, and yes, first you will want to use a playerChatted event: developer.roblox.com/en-us/api-reference/event/Player/Chatted

game.Players.PlayerAdded:Connect(function(player)
  player.Chatted:Connect(function(msg)
        -- do stuff with msg and player
  end)
end)

now you will want to use the string manipulation library: https://developer.roblox.com/en-us/api-reference/lua-docs/string

local timeCommand= "/time"
local setTimeRemote = game:GetService("ReplicatedStorage").TimeRemote

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        if message:sub(1, timeCommand:len()):lower() == timeCommand:lower() then
            local time = message:sub(timeCommand:len() + 1)
            game.Lighting:SetMinutesAfterMidnight(time * 60)
        end
    end)
end)

now for just setting it for one player you'd just utilize string.split and check for a 3rd arg which would be the player, :FireClient() that client and pretty much have that same function.. developer.roblox.com/en-us/api-reference/function/RemoteEvent/FireClient

I essentially spoonfed you the entire script, I hope you can figure it out from now on. If this helped you, please don't forget to accept this as an answer

If the script that kaspar1230 sent was not what you wanted and you instead wanted a script that only changed time locally then try putting this script in a LocalScript inside the StarterPack:

plr = script.Parent.Parent

plr.Chatted:Connect(function(msg)
	msg = msg:lower()
	if string.sub(msg, 1, 6) == "/time " then
		local timeZZ = string.sub(msg, 7)
		game.Lighting.TimeOfDay = timeZZ
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.