This is a script for changing the time in my game. When a script sends a value with the :FireServer() event, its suppost to change the time depending on the value in this script
RepStore = game:WaitForChild("ReplicatedStorage") --REPLICATED STORAGE RepStore.Events.UI.ChangeLighting.OnServerEvent:connect(function(plr, Time) --BEGIN OF SCRIPT print(Time) --SUNRISE if Time == string.lower("Sunrise") then game.Lighting.TimeOfDay = "06:10:00" print("[LIGHTING SYSTEM] - Successfully changed to Sunrise") end --DAY TIME if Time == string.lower("Day") then print("[LIGHTING SYSTEM] - Successfully changed to Day time") game.Lighting.TimeOfDay = "12:00:00" end --SUNSET if Time == string.lower("Sunset") then print("[LIGHTING SYSTEM] - Successfully changed to Sunset") game.Lighting.TimeOfDay = "18:00:00" end --NIGHT TIME if Time == string.lower("Night") then print("[LIGHTING SYSTEM] - Successfully changed to Night time") game.Lighting.TimeOfDay = "00:30:00" end if Time ~= string.lower("Sunset") or string.lower("Day") or string.lower("Night") or string.lower("Sunrise") then error("[LIGHTING SYSTEM] - Invalid Request: Does Not Exist") end end) --END OF SCRIPT
The problem is when I fire the server while testing from the command bar, it sends a player name instead of the value I requested, and the failsafe at the bottom saying its invalid. I want to send it a string value, but It never works
Command line: game.ReplicatedStorage.Events.UI.ChangeLighting:FireServer(Night)
Hello.
This is how I would do it. (Example - tested and is very functional, in other cases, it does work)
-- Server Script: (I recommend you place the following 'ServerScript' in ServerScriptService, I also added an example of basic RemoteEvent encryption for better protection, although I don't use the method I've given you, it can still be effective against those whom just find a leaked script and execute it, expecting it do work. - Future reference, you'll understand if you work on or create a popular game sometime in the future, or if you currently are). GlobalKey = "key123" -- I recommend you generate a 20-odd character key, with many symbols, numbers, letters, brackets, etc. (You will only need to change this). game.ReplicatedStorage.ChangeLighting.OnServerEvent:connect(function(Player, Key, Data) -- RemoteEvent that requires / contains three (3) arguments. if Key == GlobalKey then -- Basic encryption (If the key doesn't match, the Player will be kicked from the server to prevent RemoteEvent exploiting. You do not need to modify this line). if Data == "Night" then game.Lighting.TimeOfDay = "00:00:00" -- Equal to midnight. end else Player:Kick("[Detected]: Event tampering...") -- Self explanatory. end end) game.ReplicatedStorage.ChangeLighting:FireServer(Key, "Night") -- No need to add the 'Player' argument as it is automatically parsed via :FireServer().
I also noticed that you did the following:
game.Lighting.TimeOfDay = game.Lighting.TimeOfDay = "00:00:00"
Unfortunately, that will not work. I have corrected that for you.
Regards, StoleYourClothes.