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

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

Asked by 5 years ago
Edited 5 years ago

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?

0
Might be lemme check develop_d 53 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

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

Ad
Log in to vote
-1
Answered by 5 years ago

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)

Answer this question