Attempt to index function with RoleCharacter

So I have an issue with an error saying "Attempt to index function with RoleCharacter. I’m not sure what’s causing it but here’s the code:

remotes:WaitForChild(“ChooseRole”).OnServerEvent:Connect(function(plr, role)

	if plr and not plr.Character then
		if roles:FindFirstChild(role) then
			
			local newCharacter = roles[role].RoleCharacter:FindFirstChildOfClass("Model"):Clone()
			newCharacter.Name = plr.DisplayName
			plr.Character = newCharacter
			newCharacter.Parent = workspace
			
			for _, tool in pairs(roles[role].Tools:GetChildren()) do
				tool:Clone().Parent = plr.Backpack
			end
		end
	end
end)

The issue is coming from this line:

local newCharacter = roles[role].RoleCharacter:FindFirstChildOfClass("Model"):Clone()

Any help is appreciated! :slight_smile:

What is the value of “role” at the time this error happens?

sorry i didn’t read the whole script at first but try to print roles[role] and see what you got or print typeof(roles[role]) to see if it’s returning a Instance or function

you should’ve atleast shown where was roles declared the only idea i have that you have done something wrong while setting the roles try looking for that and what is even roles? or the role that the error appeared at

It’s returning a function asklgjaijigajn

try todo this

local getNewCharacter = roles[role]()

local newCharacter = roles[role].RoleCharacter:FindFirstChildOfClass("Model"):Clone()

newCharacter.Name = plr.DisplayName

plr.Character = newCharacter