Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to connect failed: Passed value is not a function?

So, I tryed making a script what displays a rank above their head. Some strange reason. It does not work. Error:

Any help? :) Thanks.

Attempt to connect failed: Passed value is not a function
Script 'Workspace.Overhead Ranks', Line 4

Script:

groupid = 1123228
groupn = "LavaBlast Security Group" 

game.Players.PlayerAdded:connect(onPlayerRespawned)
function onPlayerRespawned(newPlayer)
	wait(1)
	if newPlayer:IsInGroup(groupid) then
		guigroup=Instance.new("BillboardGui")
		guigroup.Parent=newPlayer.Character.Head
		guigroup.Adornee=newPlayer.Character.Head
		guigroup.Size=UDim2.new(4,0,2,0)
		guigroup.StudsOffset=Vector3.new(0,3,0)
		textgroup=Instance.new("TextLabel")
		textgroup.Size=UDim2.new(1,0,1,0)
		textgroup.BackgroundTransparency = 1
		textgroup.TextColor3 = Color3.new(255/255, 255/255, 255/255)
		textgroup.TextStrokeTransparency = 0
		textgroup.TextTransparency = 0
		textgroup.FontSize = 'Size10' 
		UnrefinedRank = newPlayer:GetRankInGroup(groupid)
		Person = newPlayer.Name

		if UnrefinedRank == 255 then 
				UnrefinedRank = "[HR] CEO" 
	
		end
		
		if UnrefinedRank == 10 then 
		UnrefinedRank = "[MR] Tier 4 Guard" 
	
		end
		
		if UnrefinedRank == 9 then 
		UnrefinedRank = "[MR] Tier 3 Guard" 
	
		end
		
		if UnrefinedRank == 8 then 
		UnrefinedRank = "[MR] Tier 2 Guard" 
	
		end
		
		if UnrefinedRank == 7 then 
		UnrefinedRank = "[MR] Tier 1 Guard" 
	
		end
		
		if UnrefinedRank == 6 then 
		UnrefinedRank = "[MR] Advanced Officer" 
	
		end
		
		if UnrefinedRank == 5 then 
		UnrefinedRank = "[LR] Officer" 
	
		end
		
		if UnrefinedRank == 4 then 
		UnrefinedRank = "[LR] Elite Security"
	
		end
		
		if UnrefinedRank == 3 then 
		UnrefinedRank = "[LR] Advanced Security" 
	
		end
		
		if UnrefinedRank == 2 then 
		UnrefinedRank = "[LR] Trained Security" 
	
		end
		
		if UnrefinedRank == 1 then
		UnrefinedRank = "[LR] In Training "
	
		end
		
		textgroup.Text = (' ' .. UnrefinedRank .. " ") 
		textgroup.Parent=guigroup
		
	end
end


function onPlayerEntered(newPlayer)
	newPlayer.Changed:connect(function (property) 
		if (property == "Character") then
			onPlayerRespawned(newPlayer)
		end
	end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

3 comments

1

Not for sure since I can't test and I'm at school but try putting the connection line after the function is defined

0

Thanks! :) Can you just put a quick answer like abc and I will accept it. :)

0

You called the first function before it even ran...

1 answer

✓ Accepted answer

What zack785 said is correct. You attempted to call the function before you defined it.

groupid = 1123228
groupn = "LavaBlast Security Group" 

function onPlayerRespawned(newPlayer)
    wait(1)
    if newPlayer:IsInGroup(groupid) then
        guigroup=Instance.new("BillboardGui")
        guigroup.Parent=newPlayer.Character.Head
        guigroup.Adornee=newPlayer.Character.Head
        guigroup.Size=UDim2.new(4,0,2,0)
        guigroup.StudsOffset=Vector3.new(0,3,0)
        textgroup=Instance.new("TextLabel")
        textgroup.Size=UDim2.new(1,0,1,0)
        textgroup.BackgroundTransparency = 1
        textgroup.TextColor3 = Color3.new(255/255, 255/255, 255/255)
        textgroup.TextStrokeTransparency = 0
        textgroup.TextTransparency = 0
        textgroup.FontSize = 'Size10' 
        UnrefinedRank = newPlayer:GetRankInGroup(groupid)
        Person = newPlayer.Name

        if UnrefinedRank == 255 then 
                UnrefinedRank = "[HR] CEO" 

        end

        if UnrefinedRank == 10 then 
        UnrefinedRank = "[MR] Tier 4 Guard" 

        end

        if UnrefinedRank == 9 then 
        UnrefinedRank = "[MR] Tier 3 Guard" 

        end

        if UnrefinedRank == 8 then 
        UnrefinedRank = "[MR] Tier 2 Guard" 

        end

        if UnrefinedRank == 7 then 
        UnrefinedRank = "[MR] Tier 1 Guard" 

        end

        if UnrefinedRank == 6 then 
        UnrefinedRank = "[MR] Advanced Officer" 

        end

        if UnrefinedRank == 5 then 
        UnrefinedRank = "[LR] Officer" 

        end

        if UnrefinedRank == 4 then 
        UnrefinedRank = "[LR] Elite Security"

        end

        if UnrefinedRank == 3 then 
        UnrefinedRank = "[LR] Advanced Security" 

        end

        if UnrefinedRank == 2 then 
        UnrefinedRank = "[LR] Trained Security" 

        end

        if UnrefinedRank == 1 then
        UnrefinedRank = "[LR] In Training "

        end

        textgroup.Text = (' ' .. UnrefinedRank .. " ") 
        textgroup.Parent=guigroup

    end
end


-- ***You do not need the "onPlayerEntered" function to run the onPlayerRespawned function, it is redundant! It wouldn't work anyways, because you cannot use the .Changed event on a player.

game.Players.PlayerAdded:connect(onPlayerRespawned)

1 comment

0

Ah. Thank chu!

This discussion is preserved as it was. New answers, comments, and votes are closed.