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)
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