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?
Yes, and yes, first you will want to use a playerChatted event: developer.roblox.com/en-us/api-reference/event/Player/Chatted
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | player.Chatted:Connect( function (msg) |
3 | -- do stuff with msg and player |
4 | end ) |
5 | end ) |
now you will want to use the string manipulation library: https://developer.roblox.com/en-us/api-reference/lua-docs/string
01 | local timeCommand = "/time" |
02 | local setTimeRemote = game:GetService( "ReplicatedStorage" ).TimeRemote |
03 |
04 | game.Players.PlayerAdded:Connect( function (player) |
05 | player.Chatted:Connect( function (msg) |
06 | if message:sub( 1 , timeCommand:len()):lower() = = timeCommand:lower() then |
07 | local time = message:sub(timeCommand:len() + 1 ) |
08 | game.Lighting:SetMinutesAfterMidnight(time * 60 ) |
09 | end |
10 | end ) |
11 | 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:
1 | plr = script.Parent.Parent |
2 |
3 | plr.Chatted:Connect( function (msg) |
4 | msg = msg:lower() |
5 | if string.sub(msg, 1 , 6 ) = = "/time " then |
6 | local timeZZ = string.sub(msg, 7 ) |
7 | game.Lighting.TimeOfDay = timeZZ |
8 | end |
9 | end ) |