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

Been having trouble with making a war tycoon and got lots of errors can any body fix my crappy code?

Asked by 4 years ago

trying to make a tycoon

got error:

  22:29:30.160 - ServerScriptService.ServerMain:16: attempt to index local 'Tycoon' (a nil value)
22:29:30.161 - Stack Begin
22:29:30.162 - Script 'ServerScriptService.ServerMain', Line 16
22:29:30.163 - Stack End

and this is the code:

function FindEmptyTycoon()

    for i,v in pairs(workspace.Tycoons.Tycoon1.RightTycoon:GetChildren()) do
        if v.TycoonInfo.Owner.Value == nil then
            return v

        end
        return nil
    end

end

game.Players.PlayerAdded:Connect(function(Player)
    local Tycoon = FindEmptyTycoon()

    Tycoon.TycoonInfo.Owner.Value = Player

    local Money = Instance.new("IntValue")
    Money.Name = Player.Name
    Money.Value = 50
    Money.Parent = game.ServerStorage.PlayerMoney

end)

1 answer

Log in to vote
0
Answered by
Gojinhan 353 Moderation Voter
4 years ago

You're not returning anything bud. Which is why tycoon is a nil value. Instead, make a variable, set it, and return the contents of that variable.

local foundtycoon

function FindEmptyTycoon()
   for i,v in pairs(workspace.Tycoons.Tycoon1.RightTycoon:GetChildren()) do
    if v.TycoonInfo.Owner.Value == nil then
            foundtycoon = v
    end
   end
   return foundtycoon
end

sorry for any crappy formatting or indenting im on mobile

0
thanks for the info but thats not the proplem the proplem is at line 16 maggi124 5 — 4y
0
i got the same error maggi124 5 — 4y
Ad

Answer this question