Why is this returning Nil?

You can write your topic however you want, but you need to answer these questions:

I have been having this issue where I make a variable in a client Script and I want to call to a Server script to get the value of a datastore and return the value(I’m using DataStore2) , and when I print the value it says nil, but in the serverscript I print the dataName:Get(0) and it return the value I’m looking for. so I dont know if Im being stupid and not looking hard enough, but I really have no idea, please help!

-- Client Script
local Value = Signals.UIEvents.GetCurrentUpgrade:FireServer("CurrentUpgrade")
print(Value) --Prints nil
--ServerScript
Signals.UIEvents.GetCurrentUpgrade.OnServerEvent:Connect(function(plr,dataName)
	local dataStore = DataStore2(dataName, plr)

	local newValue = dataStore:Get(0)
    print(newValue)  -- prints the value I want "26"
	return newValue	
end)

Why is this happening?

thank you in advance!

You need to use a RemoteFunction to return things, and you need to set it up like this.

-- Client Script
local Value = Signals.UIEvents.GetCurrentUpgrade:InvokeServer("CurrentUpgrade")
print(Value) --Prints nil
--ServerScript
Signals.UIEvents.GetCurrentUpgrade.OnServerInvoke = function(plr,dataName)
	local dataStore = DataStore2(dataName, plr)

	local newValue = dataStore:Get(0)
    print(newValue)  -- prints the value I want "26"
	return newValue	
end

Ok, so I was being stupid and forgot about that, THANK YOU SO MUCH!!

1 Like