Attempt to call a nil value

  1. What do you want to achieve?
    I Would like to make an admin panel where I can change the time of day.

  2. What is the issue?
    I get an error saying “Attempt to call a nil value” regardless of the fact that I’m calling a value from a NumberValue

  3. What solutions have you tried so far?
    I’ve looked here on the forum and other places, and I couldn’t find any situations similar to mine. Other situations encompassed other concepts that have no relation to my scripts

As I stated above I am trying to make an admin console where I can change the time of day from a GUI button (I have the button part working). When I click the button, the function seems to go through, but I get an error in the output that says: “Attempt to call a nil value” and I’ve been stumped for a while now.

The local script (where the player presses the button and then a signal is sent to the remote event)


function leftClick()
	print("Left mouse click")
	
	local ReplicatedStorage = game:GetService("ReplicatedStorage")

	local remoteEvent = ReplicatedStorage:WaitForChild("TimeChange")
	local Time = 330 --Sunrise time
	-- Fire the remote event
	remoteEvent:FireServer(Time)
end


script.Parent.MouseButton1Click:Connect(leftClick)

The server script


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("TimeChange")
local Timeval = script.Parent:WaitForChild("Timeval")
-- Create a new part
local function ChangeTime(Time)
	print(Time)
	Timeval.Value = Time
end

-- Call "onCreatePart()" when the client fires the remote event
remoteEvent.OnServerEvent:Connect(ChangeTime())

For your OnServerEvent function. You need to remove those two brackets like so:
remoteEvent.OnServerEvent:Connect(ChangeTime)

Also, when you print time, It would print your player’s name, rather then the actual value. This is because when calling fireserver, the player is always passed. So when receiving it on the server, you need to add your player argument like so.
local function ChangeTime(Player, Time)

2 Likes

Would I also need to do (player,Time) when sending?

No the player is always passed. You just need it on the server :slight_smile:

Thank you so much! (this is my first post on the forum so i appreciate the kindness!)