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

Says its not a function yet it works?

I found this script and liked it but I wanted to know why it works with line 3 being not a function. I also though want to fix it because it says in my console that line 3 can not be connected because its not a function? Any help I tried making it a function and it broke the whole script.

groupid = 2758901 

game.Players.PlayerAdded:connect(onPlayerRespawned)
function onPlayerRespawned(newPlayer)
	wait(1)
	if newPlayer:IsInGroup(groupid) then
		local gui=Instance.new("BillboardGui")
		gui.Parent=newPlayer.Character.Head
		gui.Adornee=newPlayer.Character.Head
		gui.Size=UDim2.new(4,0,2,0)
		gui.StudsOffset=Vector3.new(0,3,0)
		local texta=Instance.new("TextBox")
		texta.Size=UDim2.new(1,0,2,0)
		texta.BackgroundTransparency = 1
		texta.Text = ("- " .. newPlayer:GetRoleInGroup(groupid) .. " -")
		texta.Parent=gui
		end
	end

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

game.Players.PlayerAdded:connect(onPlayerEntered)

2 comments

0

Why are there -8 points?

0

I have no clue.

1 answer

✓ Accepted answer

The reason line 3 doesn't activate the function on line 4 is due to how Lua compiles it's coding. It'll read the code from the top down, and if you try to make a function call before the function has been compiled, it will result in an error. To fix this, simple put line 3 below the function on line 4! (Somewhere around line 19)

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