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

What is wrong with this script?

Asked by
IcyEvil 260 Moderation Voter
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I just cant understand what is wrong with it, there is an error, it is marked at --

function findPlayer(name)
    for _, player in pairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
            return true end -- 'end' expected(to close 'if' at line 3 near 'return
        end
    end
end

1 answer

Log in to vote
0
Answered by 9 years ago

I don't think your able to do that. :P Do this instead;

function findPlayer(plr) --Our function
for i,v in pairs(game.Players:GetPlayers()) do --Gets all the players that are currently in game.Players
if v.Name:lower():find(plr:lower()) then --If the function matches plr to the Player's name then
return v --It'll return the player
end --The end to end the 'if' statement
end --The end to end the code for the 'for' loop
return nil --Will return nil
end --The end to end the function

Hope this helped!

0
Ima test it out IcyEvil 260 — 9y
0
`return nil` is superfluous. A function without a `return` will already evaluate to `nil`. If you did want to return a tuple (multiple values) you could `return v, true`, however, this is unnecessary since `v` will be truthy while `nil` will not be. BlueTaslem 18071 — 9y
0
Oh, sorry, I didn't really know that. Guess I'm still a bit Out-of-date. Haha! :P TheeDeathCaster 2368 — 9y
Ad

Answer this question