First, I’ve got an error from this script. This script is used to check the Attribute server, and returns it to client.
local RemoteFunction = game:GetService("ReplicatedStorage"):WaitForChild('EventChanged')
function playerAttributeRequired(player, attribute, unit) -- client site input ("FieldOfView", player)
return unit:GetAttribute(attribute) -- attempt to call a nil value
end
RemoteFunction.OnServerInvoke = playerAttributeRequired
I’m so confused why would that happen. I was guessing maybe "FieldOfView" is not considered to be a string, so I have chenged my code to this:
Try using tonumber() instead of string() function. Because FieldOfView Property is numeric data type. Or, if you need string to be returnd, use tostring() instead of string() as @Kacper said.
local RemoteFunction = game:GetService("ReplicatedStorage"):WaitForChild('EventChanged')
function playerAttributeRequired(player, attribute, unit)
return unit:GetAttribute(tostring(attribute))
end
RemoteFunction.OnServerInvoke = playerAttributeRequired
I think that means my parameter is string for sure, but I need to solve this problem:
Why would a string parameter don’t work?
Unit is a nil value. Are you sure when you’re invoking the server you are not passing a player reference?
Your invokeserver should look like this RemoteFunction:InvokeServer(attribute, unit)
I see what happened. I’m so careless by the way.
It was a RemoteFunction for EventRequired. But I have set my RemoteFunction to EventChanged, which is another RemoteFunction.
I have currented that and solved the question. I’m so sorry about that.
local RemoteFunction = game:GetService("ReplicatedStorage"):WaitForChild('EventChanged')
-- Should be:
local RemoteFunction = game:GetService("ReplicatedStorage"):WaitForChild('EventRequired')