Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Says its not a function yet it works?

Asked by 8 years ago

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)
0
Why are there -8 points? Wutras 294 — 8y
0
I have no clue. Conmmander 479 — 8y

1 answer

Log in to vote
1
Answered by
Uglypoe 557 Donator Moderation Voter
8 years ago

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)

Ad

Answer this question